How to publish DACPAC file to a SQL Server database project via SQLPackage.exe of SSDT?

我是研究僧i 提交于 2019-12-21 03:51:05

问题


I'm using SSDT for Visual Studio 2012 here and using its command-line tool SQLPackage.exe to publish a .dacpac file.

I want to publish that to an SQL Server database project. I'm trying to use parameter at this guide but cannot find ways how to do it.

How can I do that?


回答1:


Are you trying to publish to a Database, or create a database project from a dacpac? These are two different things.

  • To create a database project based on a dacpac, create a new SQL Server Database Project in Visual Studio. Then right-click on the project in Solution Explorer and choose "Import -> Data-tier Application (*.dacpac)" and select your dacpac. That will convert the contents of the dacpac into scripts in the project, and if you choose "Import database settings" the database options will be set based on the settings in the dacpac. Unfortunately there's no way to do this via a command line tool that I'm aware of.

  • To use SqlPackage.exe to publish to a database, the guide you linked to has all the options. A simple command would be "sqlpackage /a:publish /sf:db1.dacpac /tsn:localhost /tdn:db1" to publish dacpac "db1" to a database "localhost\db1". For other publish options type "sqlpackage /a:publish /?" to get the list of applicable actions on the command line.




回答2:


Using Powershell you can deploy to either to Standard On-premise SQL Instances or to Azure SQL Instance. The connection string and other properties will be fed from the PublishProfile

$PublishPath = "Path for the log"
$dacpac = "dbname.dacpac"
$publishProfile = "dbname.xml" # Publish profile xml for Publishing the database project

# Generate Deploy Report
$DeployReport =  ".\sqlpackage.exe /Action:DeployReport /Sourcefile:$dacpac `
                   /pr:'$publishProfile' /outputpath:$PublishPath"

Invoke-Expression $DeployReport

# Generate Script Report
$GenerateScript =  ".\sqlpackage.exe /Action:Script /Sourcefile:$dacpac `
                     /pr:'$publishProfile' /outputpath:$PublishPath"

Invoke-Expression $GenerateScript

# Database Publish
$publish = ".\sqlpackage.exe /Action:Publish /Sourcefile:$dacpac `
             /pr:'$publishProfile'"

Invoke-Expression $publish | Out-File $PublishPath


来源:https://stackoverflow.com/questions/20513530/how-to-publish-dacpac-file-to-a-sql-server-database-project-via-sqlpackage-exe-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!