Search code examples
sqlsql-servervisual-studio-2012visual-studio-2013sql-server-2012-datatools

How to change the connection in Sql Server Data Tools Editor in Visual Studio


My goal is to keep SQL Server stored procedures under source control. I also want to stop using SQL Server Management Studio and use only Visual Studio for SQL related development.

I've added a new SQL Server Database project to my solution. I have successfully imported my database schema into the new project, and all the SQL objects (tables, stored procedures) are there in their own files.

enter image description here

I know that now if I run (with F5) the .sql files then my changes will be applied to my (LocalDB). This if fine, but what if I want to very quickly run something on another machine (like a dedicated SQL Server shared by the entire team)? How can I change the connection string of the current .sql file in the Sql Server Data Tools editor?

I have the latest version of Sql Server Data Tools extension for Visual Studio 2012 (SQL Server Data Tools 11.1.31203.1). I don't know if this is related to the current version, but I cannot find anymore the Transact-SQL Editor Toolbar.

I have also tried to Right-click on the sql editor, choose Connection -> Disconnect. If I do the reverse (Connection -> Connect...) the editor directly connects automatically (probably to my LocalDB), without asking me a dialog to choose my connection.

Another strange thing I've observed, if I try to run a simple SQL query (like select * from dbo.ApplicationUser I receive the following message (even if the autocomplete works): enter image description here

Thanks.

(Note: I have the same issue with Visual Studio 2013)


Solution

  • This should be a fairly simple and straight-forward thing to do, that is, if you are using SSDT version 12.0.41025.0 (or newer, one would suppose):

    1. Do either:
      1. Go to the SQL menu at the top of the Visual Studio window
      2. Right-click inside of the SQL editor tab
    2. Go to Connection ->
    3. Select Change Connection

    Then it will display the "Connect to Server" modal dialog window.

    If you do not see the options for "Disconnect All Queries" and "Change Connection...", then you need to upgrade your SSDT via either: