2011-12-03 164 views
7

我有一個針對SQL Server 2012 RC0數據庫的SQL Server數據庫項目。該項目是在Visual Studio 2010 + SQL Server數據工具CTP4中創建的。項目類型與常規Visual Studio 2010數據庫項目不同(它是下一版SQL Developer Tools CTP3 Juneau)。通過命令行部署SQL Server數據庫項目(SSDT)

它在IDE中部署得很好。我怎樣才能通過命令行部署它?

我試過VSDBCMD.exe,但它期望一個.deploymanifest文件不是由新項目類型創建的。

回答

24

使用sqlpackage.exe,位於C:\Program Files\Microsoft SQL Server\{version}\DAC\binC:\Program Files (x86)\Microsoft SQL Server\{version}\DAC\bin其中{version} = 110(SQL Server 2012中),120(SQL服務器2014)等

的命令行參數:

/Action:{Extract|Report|Publish|Script} Specifies the action to be performed. 
             (short form /a) 

/Quiet[+|-]        Specifies whether detailed feedback is 
             suppressed. Defaults to False. (short 
             form /q) 

/OverwriteFiles[+|-]      Specifies if sqlpackage.exe should 
             overwrite existing files. Specifying 
             false causes sqlpackage.exe to abort 
             action if an existing file is 
             encountered. Default value is True. 
             (short form /of) 

/SourceServerName:<string>    Defines the name of the server hosting 
             the source database. (short form /ssn) 

/SourceDatabaseName:<string>    Defines the name of the source 
             database. (short form /sdn) 

/SourceUser:<string>      For SQL Server auth scenarios, defines 
             the SQL Server user to use to access 
             the source database. (short form /su) 

/SourcePassword:<string>     For SQL Server auth scenarios, defines 
             the password to use to access the 
             source database. (short form /sp) 

/SourceTimeout:<int>      Specifies the timeout for establishing 
             a connection to the source database in 
             seconds. (short form /st) 

/SourceEncryptConnection[+|-]   Specifies if SQL encryption should be 
             used for the source database 
             connection. (short form /sec) 

/SourceTrustServerCertificate[+|-]  Specifies whether to use SSL to 
             encrypt the source database connection 
             and bypass walking the certificate 
             chain to validate trust. (short form 
             /stsc) 

/SourceConnectionString:<string>   Specifies a valid SQL Server/Azure 
             connection string to the source 
             database. If this parameter is 
             specified it shall be used exclusively 
             of all other source parameters. (short 
             form /scs) 

/SourceFile:<string>      Specifies a source file to be used as 
             the source of action instead of a 
             database. If this parameter is used, 
             no other source parameter shall be 
             valid. (short form /sf) 

/TargetServerName:<string>    Defines the name of the server hosting 
             the target database. (short form /tsn) 

/TargetDatabaseName:<string>    Specifies an override for the name of 
             the database that is the target of 
             sqlpackage.exe Action. (short form 
             /tdn) 

/TargetUser:<string>      For SQL Server auth scenarios, defines 
             the SQL Server user to use to access 
             the target database. (short form /tu) 

/TargetPassword:<string>     For SQL Server auth scenarios, defines 
             the password to use to access the 
             target database. (short form /tp) 

/TargetTimeout:<int>      Specifies the timeout for establishing 
             a connection to the target database in 
             seconds. (short form /tt) 

/TargetEncryptConnection[+|-]   Specifies if SQL encryption should be 
             used for the target database 
             connection. (short form /tec) 

/TargetTrustServerCertificate[+|-]  Specifies whether to use SSL to 
             encrypt the target database connection 
             and bypass walking the certificate 
             chain to validate trust. (short form 
             /ttsc) 

/TargetConnectionString:<string>   Specifies a valid SQL Server/Azure 
             connection string to the target 
             database. If this parameter is 
             specified it shall be used exclusively 
             of all other target parameters. (short 
             form /tcs) 

/TargetFile:<string>      Specifies a target file (i.e., a 
             .dacpac files) to be used as the 
             target of action instead of a 
             database. If this parameter is used, 
             no other target parameter shall be 
             valid. This parameter shall be invalid 
             for actions that only support database 
             targets. (short form /tf) 

/Properties:<string>      A name value pair for a Publish 
             property, {PropertyName}={Value}. 
             Refer to the help for the Publish 
             action for valid property names. 
             (short form /p) 

/Variables:<string>      Optional only if /Action:Publish is 
             specified. Valid values for parameter 
             name shall be SQL Command variables 
             specified in the .dacpac file only. 
             Parameter names specified that are not 
             declared in the .dacpac shall result 
             in an error. Valid command variable 
             values shall be context-specific based 
             on the command variable itself (e.g., 
             database name vs. schema names). 
             (short form /v) 

/Profile:<string>      Optional if /Action:Publish is 
             specified. Valid value is a file path 
             to a Publish Profile. A user shall be 
             able to use a Publish Profile to 
             define the collection of Publish 
             Properties to use for a Publish 
             episode. (short form /pr) 

/OutputPath:<string>      Required if /Action:Report or 
             /Action:Script is specified. Valid 
             value is a file path to where the 
             comparison report shall be written. 
             (short form /op) 

@<file>         Read response file for more options. 

例如:
sqlpackage.exe /Action:Publish /SourceFile:C:\DbProject\bin\Debug\DbProject.dacpac /TargetServerName:localhost /TargetDatabaseName:TestDb

With t ARGET存儲在個人資料數據庫的詳細信息:
sqlpackage.exe /Action:Publish /SourceFile:C:\DbProject\bin\Debug\DbProject.dacpac /Profile:C:\DbProject\LocalDb.publish.xml

如果你得到錯誤「無法連接到目標服務器」,那麼請確保您使用sqlpackage.exe的正確版本(見here有詳細介紹)。

+1

[在線文檔(http://msdn.microsoft.com/en-us/library/hh550080%28VS.103%29.aspx) –

+0

也適用於Visual Studio 2013中的SSDT。 – Keith

+0

當指定了兩者時,/ TargetConnectionString是否覆蓋/ Profile? @Keith – Json

2

如果你是一個受虐狂的人,微軟也會在'使用PowerShell'的幌子下提供documentation on deploying the DACPAC via SMO

當然你也可以從PowerShell中也稱sqlpackage ...

+0

偉大的鏈接文章。但請花時間擴展您的答案與文章的相關摘錄,以防止可能的鏈接腐爛!謝謝。 – bPratik

相關問題