无法在安装了SQL Server 2012的Windows Server 2012上使用msbuild运行dbdeploy组件

时间:2014-11-01 13:00:52

标签: sql-server-2012 windows-server-2012 msbuild-4.0 dbdeploy

我正在尝试在安装了SQL Server 2012的Windows服务器2012上使用MSBuild运行dbdeploy组件。

在运行msbuild脚本时,我收到以下错误:

"E:\TestDeployment\Test.proj" (UpgradeDatabase target) (1) ->(dbDeploy target) ->
  E:\TestDeployment\Test.proj(212,5): error : Unexpected System.IO.FileNotFoundException
error executing SQL command: -- BEGINNING TRANSACTION\r
E:\TestDeployment\Test.proj(212,5): error : PRINT 'Beginning transaction'\r
E:\TestDeployment\Test.proj(212,5): error : BEGIN TRANSACTION \r
E:\TestDeployment\Test.proj(212,5): error : GO\r
E:\TestDeployment\Test.proj(212,5): error : \r
E:\TestDeployment\Test.proj(212,5): error : -- Drop Table ChangeLog\r
E:\TestDeployment\Test.proj(212,5): error : Print 'Checking for Table ChangeLog'\r
E:\TestDeployment\Test.proj(212,5): error : IF (NOT EXISTS(SELECT * FROM sys.objects WHER
E [object_id] = OBJECT_ID(N'[dbo].ChangeLog') AND [type]='U'))\r
E:\TestDeployment\Test.proj(212,5): error : BEGIN\r
E:\TestDeployment\Test.proj(212,5): error :         CREATE TABLE dbo.ChangeLog \r
E:\TestDeployment\Test.proj(212,5): error :         (\r
E:\TestDeployment\Test.proj(212,5): error :                 change_number INTEGER NOT NUL
,\r
E:\TestDeployment\Test.proj(212,5): error :                 delta_set VARCHAR(10) NOT NUL
,\r
E:\TestDeployment\Test.proj(212,5): error :                 start_dt DATETIME NOT NULL,\r
E:\TestDeployment\Test.proj(212,5): error :                 complete_dt DATETIME NULL,\r
E:\TestDeployment\Test.proj(212,5): error :                 applied_by VARCHAR(100) NOT N
LL,\r
E:\TestDeployment\Test.proj(212,5): error :                 description VARCHAR(500) NOT
ULL\r
E:\TestDeployment\Test.proj(212,5): error :         )\r
E:\TestDeployment\Test.proj(212,5): error : \r
E:\TestDeployment\Test.proj(212,5): error :         IF @@ERROR<>0 OR @@TRANCOUNT=0 BEGIN
IF @@TRANCOUNT>0 ROLLBACK SET NOEXEC ON END\r
E:\TestDeployment\Test.proj(212,5): error :                 \r
E:\TestDeployment\Test.proj(212,5): error :         ALTER TABLE ChangeLog ADD CONSTRAINT
PK_ChangeLog PRIMARY KEY (change_number, delta_set)\r
E:\TestDeployment\Test.proj(212,5): error :         IF @@ERROR<>0 OR @@TRANCOUNT=0 BEGIN
IF @@TRANCOUNT>0 ROLLBACK SET NOEXEC ON END\r
E:\TestDeployment\Test.proj(212,5): error : END\r
E:\TestDeployment\Test.proj(212,5): error : GO\r
E:\TestDeployment\Test.proj(212,5): error : IF @@ERROR<>0 OR @@TRANCOUNT=0 BEGIN IF @@TRA
NCOUNT>0 ROLLBACK SET NOEXEC ON END\r
E:\TestDeployment\Test.proj(212,5): error : GO\r
E:\TestDeployment\Test.proj(212,5): error : \r
E:\TestDeployment\Test.proj(212,5): error : UPDATE dbo.ChangeLog SET complete_dt = getdat
e() WHERE complete_dt IS NULL\r
E:\TestDeployment\Test.proj(212,5): error : GO\r
E:\TestDeployment\Test.proj(212,5): error : \r
E:\TestDeployment\Test.proj(212,5): error : IF @@ERROR<>0 OR @@TRANCOUNT=0 BEGIN IF @@TRA
NCOUNT>0 ROLLBACK SET NOEXEC ON END\r
E:\TestDeployment\Test.proj(212,5): error : GO\r
E:\TestDeployment\Test.proj(212,5): error : \r
E:\TestDeployment\Test.proj(212,5): error : -- COMMITTING TRANSACTION\r
E:\TestDeployment\Test.proj(212,5): error : IF @@TRANCOUNT>0\r
E:\TestDeployment\Test.proj(212,5): error : BEGIN\r
E:\TestDeployment\Test.proj(212,5): error :         PRINT 'Committing transaction'\r
E:\TestDeployment\Test.proj(212,5): error :         COMMIT TRANSACTION \r
E:\TestDeployment\Test.proj(212,5): error : END\r
E:\TestDeployment\Test.proj(212,5): error : GO\r
E:\TestDeployment\Test.proj(212,5): error : \r
E:\TestDeployment\Test.proj(212,5): error : SET NOEXEC OFF\r
E:\TestDeployment\Test.proj(212,5): error : GO\r
E:\TestDeployment\Test.proj(212,5): error :
E:\TestDeployment\Test.proj(212,5): error : Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

上面的脚本在我的开发框中以及安装了SQL SERVER 2008 R2的盒子(Windows Server 2008 R2)上运行良好。一旦我尝试在安装了SQL SERVER 2012的新盒子上测试它就会出现问题。

有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

检查有效工作的机器与不工作的机器之间的环境变量。这假设您正在打开命令提示符,然后运行MSBuild。

我的计算机上安装了SQL Server 2012,并在以下位置找到了BatchParser.DLL:

  • C:\ Program Files(x86)\ Microsoft SQL Server \ 110 \ DTS \ Binn
  • C:\ Program Files(x86)\ Microsoft SQL Server \ 110 \ Tools \ Binn
  • C:\ Program Files(x86)\ Microsoft SQL Server \ Client SDK \ ODBC \ 110 \ Tools \ Binn

因此,错误的最可能原因是您完全错过了一个环境变量,它指向其中一个。

据我所见,它们只在我的PATH变量中。

如果您在任何这些位置找不到此DDL,则需要按照这些S.O.中的讨论安装SMO。问题:

修改
最后要检查的是,是否还有 C:\ Program Files(x86)\ Microsoft SQL Server \ 100 文件夹,然后该文件夹将具有 DTS \ Binn 和/或其中的工具\ Binn 文件夹。我的猜测是,基于错误

  

无法加载文件或程序集'Microsoft.SqlServer.BatchParser,Version = 10.0.0.0

它专门寻找2008版本的SMO,这是您的开发盒所具有的,但不在仅包含SQL 2012的新盒子上。您的选择是:

  • 尝试将“batchparser.dll”从开发框复制到新的SQL 2012服务器并将其放在 C:\ Program Files(x86)\ Microsoft SQL Server \ 110 \ Tools \ Binn 文件夹。
  • 在新的SQL Server 2012服务器上下载并安装包含SMO的SQL Server 2008 R2 Feature Pack。展开“安装说明”部分,然后转到“Microsoft®SQLServer®2008R2共享管理对象”以获取正确的MSI。

答案 1 :(得分:0)

我进一步分析了这个问题,发现我需要更新dbDeploy组件。我使用在URL:http://dbdeploynet2.codeplex.com/找到的DbDeploy.Net 2更新了现有项目,然后根据提到的示例对现有的msbuild脚本进行了更改,它开始正常工作。我在实施后遇到的唯一问题是使用DedicatedAdminConnection =&#34; True&#34;给出了一个与SQL连接相关的错误。因此我不想使用DedicatedAdminConnection =&#34; True&#34;在msbuild脚本中。