28

This is a new phenomenon I am seeing, my Database name is: MySQLCLR, there is a script that always give this name in it:

:setvar DatabaseName "MySQLCLR"

all of a sudden now, everytime I make any change to my sqlclr project code and re-compile, the new output script has the name with an added _1 in it, like the following:

:setvar DatabaseName "MySQLCLR_1"

Another change to the code and subsequent build will generate this:

:setvar DatabaseName "MySQLCLR_1_1"

and so forth....

any idea why this is happening?

VS2012, MSSQL2008 R2 on windows 2008 R2

Cœur
  • 32,421
  • 21
  • 173
  • 232
Pacman
  • 1,955
  • 2
  • 32
  • 64
  • 2
    Are you using SSDT? It may be completely unrelated but your issue sounds very similar to an issue mentioned in this [article](http://arcanecode.com/2012/08/07/sql-server-data-tools-in-visual-studio-2012publish-database-profile/). They could be related. – DMK Feb 06 '13 at 17:17
  • Indeed it does seem to be the same 'bug' ... "As I write this however, there is a bug with SSDT. When you click the “Add Profile to project” button it immediately adds a profile with the original default name. Then when you click the Save button in the dialog above, it adds the profile again, totally ignoring the name you give it. Instead it uses the default name again, only this time with an _1" – Paul Zahra Feb 11 '13 at 10:08
  • This used to work for me until recently, is there a way around it ? I dont recall ever using the publish dialog. – Pacman Mar 07 '13 at 18:32
  • Do you have any other database references in your project? – Alex Filipovici Mar 14 '13 at 09:59

4 Answers4

3

Go to your project's properties, go to Debug and under the Target Connection String section, click on Restore Default.

Maybe you'll need to install the SQL Server Data Tools - December 2012 update.

Alex Filipovici
  • 29,732
  • 5
  • 50
  • 76
1

I think it is because it saves the database at the same location without overwriting the old database, is your database connected in visual studio? if it is, try this:

Search for your database in the solution explorer example: "database.sdf". click on the database and look in the properties. There should probably be a property which is for default "don't copy" or something, change that to copy if newer and then recompile. does the problem then still exists?

Andrew Barber
  • 37,547
  • 20
  • 91
  • 118
Joey De Laat
  • 91
  • 12
1

I have seen visual studio cause this issue with other SQL project files as well. In my case, it was because their are files already in that location with the name you are trying to give it. Check that directory and see if the files already exist. If they do, delete them and then your script should behave as expected.

I ran into this issue when people would do a bad TFS merge and left hanging generated files on their local computer. When they went to re-generate them, the generator incremented all of the file names in a similar fashion to what you are describing.

lehn0058
  • 19,077
  • 14
  • 65
  • 107
  • 1
    This is NOT the file name that is increment in name, it's the Database name inside the generated sql script. Note that the [outfilename].sql is always the same in my case – Pacman Mar 08 '13 at 17:11
0

I ran into this too. The setting that you must change is in the Project Properties / DEBUG tab on the left. (Right click on your database project, select properties.) In there, you will see a target connection string. In there you will see the hated _1 (or _2) appended to your database name. THIS is where you need to make the edit so that your deployment scripts (e.g. mydatabase.sql) that is generated as part of the deploy step has the right database name.

Yes, this setting even affects the RELEASE version too, even though it is in the debug tab. Go figure.

Simply select the 'Restore Default' button and the appended number should disappear. Hit the green > button or f5 (even in release mode) and you will get a nice clean deployment script with the right name in it.