Tag: sql server data tools

SQLCMD模式下的ServerConnection.ExecuteNonQuery

我正在使用Microsoft Data-Tier Application框架来创建基于DacPackage对象的部署脚本。 我试图使用Microsoft.SqlServer.Management.Smo.Server类来执行此脚本… SqlConnection deployConnection = new SqlConnection(connBuilder.ToString()); deployConnection.Open(); Server server = new Server(new ServerConnection(deployConnection)); server.ConnectionContext.ExecuteNonQuery(deployScript); 然而,这错误与…… Unhandled Exception: Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. —> System.Data.SqlClient.SqlException: Incorrect syntax near ‘:’. 我知道这个问题的答案是我需要处于SQLCMD模式,但我不知道如何告诉我的ServerConnection在所述模式下执行。 我想我的问题不像我在标题中说的那样具体。 我真正需要做的是通过.Net框架执行从DacPackage生成的脚本。 谁能帮我这个?