29

In visual studio 2012 sqlproj, the default connection button always connect to the (localdb)\Projects by default. How do I change that? Every time I need to disconnect and connect again to change the server.

suresh2
  • 1,129
  • 2
  • 15
  • 25
  • @Yang..suppose I need to connect with Microsoft Nav database using Webservices, then how can I do it? – sonsha Sep 28 '16 at 10:51

3 Answers3

52

Check the properties of your database project. Under Debug tab, there's option "Target Connection String". Change that to the server and database you want to use.

Even Mien
  • 44,393
  • 43
  • 115
  • 119
Yang
  • 536
  • 5
  • 3
  • 1
    I am honestly thinking that the Database Projects > SSMS built-in Solution Explorer. For the fact that you can also do data comparisons, schema comparisons and everything else inbetween for daily development, I believe that this kicks ass bigtime. Your answer just swayed my opinion on Database projects. – Eon Dec 08 '14 at 09:19
  • 1
    By default this setting is saved in *your-database.user* settings file. If you use source control and have excluded *.user* files from your commits, be sure to add this file manually or un-ignore *.user* files. Another possibility is to take `` tag together with contents from *.user* file and copy them to *.sqlproj* file. – Gabrielius Mar 20 '17 at 16:42
  • Is there a way to set the connection using some parameter? We want to do it from VSTS. – Kangkan Oct 18 '18 at 13:32
12

To change default connection

  1. On the menu, choose Tools-> Options -> Database tools
  2. On the data connections enter the SQL server Instance name that you want to use
  3. Press OK

this is from http://xprog.blogspot.com/2012/08/visual-studio-2012-change-default-sql.html

To change connection on a file by file basis

This worked for me. I had a sql file with BuildAction=Build and it was missing the sql connection toolbar.

  1. in solution explorer, click on the sql file
  2. change its BuildAction to None
  3. open the file (if its already open, close and reopen)

now you will get the connection toolbar.

you will have to remember to change the build action back when you are done with your maintenance.

BraveNewMath
  • 8,090
  • 5
  • 46
  • 51
  • 2
    Hi Thanks for the answer. Connection tool bar is available for us. the question is every time I press the Connect icon in the connection tool bar, it initially automatically connects to the local db. you must click the disconnect icon to disconnect from the local db and click the connect icon again so that the connect to server dialogue box appears. I coudn't find the way to connect to the different db in one step. – suresh2 Jun 20 '13 at 13:40
2

To change the default db In Solution Explorer, right click on your DB project, select Properties Go to Debug Tab Under 'Target Connection String' click EDIT enter you sql server details and save.