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

2

13

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?

Natator answered 11/12, 2013 at 7:55 Comment(1)
Examples of using sqlpackage.exe: #8372379Volitant
A
13

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.

Alible answered 11/12, 2013 at 18:24 Comment(1)
I want to update the schema of an external database to the database projectNatator
R
3

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
Radio answered 18/4, 2015 at 4:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.