Reputation: 5366
It's been a while sinse I used database projects and I'm tearing my hair out trying to figure out where to set the database name for this project.
I've tried in the SQLCMD variables section, but it doesn't let me (error below). I guess this section is to define your own variables (the same happens if I try $(DatabaseName))
The help link also doesn't work which is really helpful (goes to this dead link)
Upvotes: 8
Views: 8804
Reputation: 101
I know this is an old topic, but I just encountered the problem.
Follow this steps to set DatabaseName variable:
I hope it helps.
Upvotes: 5
Reputation: 21224
You can override DatabaseName using one of the following methods:
TargetDatabaseName
argument. Example: sqlpackage.exe /Action:Publish /SourceFile:C:\DbProject\bin\Debug\DbProject.dacpac /TargetServerName:localhost /TargetDatabaseName:TestDb
(See here for all sqlpackage.exe arguments)Upvotes: 8
Reputation: 300
I didn't want to use the publish feature but I did find a way to change the database name. It seems that the database name defaults to the project name. So, you can just rename the project to match your database name and that will do it. In my case, the project name and my desired database name are different. So, to change it, you can rename the project TWICE according to these steps:
Rename the project to the name you want your database to be. When VS asks, "Do you also want to rename the target database for the project to 'xxx' ?", choose Yes.
Rename the project back to what you want your project name to be. You'll get the same dialog but this time choose No.
This told me that the information is saved separately somewhere so I looked in the .sqlproj file and sure enough, there is a <TargetDatabase>
element. So, another way to do it would be to just manually edit the .sqlproj file and change the TargetDatabase to your desired database name.
I'm using Visual Studio Community 2019.
Upvotes: 10