Greg
Greg

Reputation: 3522

Specify a connection string when building sqlproj

We have started using local SQL Servers (SQL 2012) for development. We have a tool that calls MSBUILD to deploy a SQL Project (.sqproj) to either our local, dev & test databases.

A requirement has come up where we want to use that tool to deploy to other local databases - it's a rare thing to do but needed.

We have setup a .publish.xml file for each normal environment (dev.publish.xml, test.publish.xml, local.publish.xml, where local points to (local)\SQL2012).

We normally run:

msbuild.exe /t:build;publish /p:SqlPublishProfilePath="Local.publish.xml" "c:\workspaces\greg\...\databaseProject.sqlproj"

That works fine as it takes the connection string from the local.publish.xml file and deploys the sql project to our local database.

I'm not sure how to overwrite the publish file to make it point to a different database

I've tried

msbuild.exe /t:build;publish /p:SqlPublishProfilePath="Local.publish.xml" /p:TargetConnectionString="Data Source=SomeOtherPC\SQL2012;Integrated Security=True;Pooling=False" "c:\workspaces\greg\...\databaseProject.sqlproj"

but it still points to (local)\sql2012 instead of SomeOtherPC\SQL2012

Upvotes: 3

Views: 1231

Answers (1)

Bigwave
Bigwave

Reputation: 2206

Create a different publish profile for this and populate it with the required details (SomeOtherPC, SQL 2012, etc.)

SomeOtherPC.publish.xml

And pass that as the paramter to MSBuild

msbuild.exe /t:build;publish /p:SqlPublishProfilePath="SomeOtherPC.publish.xml"

Upvotes: 2

Related Questions