.NET Daily


How to easily get a database connection string with Visual Studio

Posted on .

How to easily get a database connection string with Visual Studio


Because I’m working on several projects at a time, it’s very hard for me to remember any connectivity data for any of the projects. Same thing for connection strings. However, with the help of Visual Studio I can generate a connection string pretty fast if I know the server address and the credentials.

Here are the steps I follow to generate a new connection string:

  • 1. From the “Server Explorer” toolbar in Visual Studio you need to click on the “Connect to Database” button.
    Visual Studio - Server Explorer

    Visual Studio – Server Explorer

  • 2. From the popping dialog box you need to select “Microsoft SQL Server” if of course you connect to a Microsoft SQL Server or any other database provider suitable to your database.
  • 3. In the next popping dialog you’ll need to specify the server name or server address together with the username and password. If the credentials are correct, then in the “Connect to a database” you should see the databases available for the selected user or the server. You need to select your database and click OK.
    Visual Studio - Add Connection

    Visual Studio – Add Connection

  • 4. Once the connection has been successfully created, you should see the new connection in the “Server Explorer” toolbar. To get the connection string, you need to right click on it, then click on the “Properties” option and there you go: on the “Connection” panel you should see a connection string field. You can copy that text and replace the password which is not displayed by default and that it!
    Visual Studio - Connection String

    Visual Studio – Connection String

Notes and Issues:

  • If your database is hosted on your computer is better for security reasons to choose “Use Windows Authentication” from the “Add Connection” panel.
  • If the SQL Server instance that is installed on your computer is not visible in the servers dropdown nor you can connect to it with computer name or IP then you need to check whether the service called “SQL Server Browser” is turned on. To check this, you need to go to Control Panel -> Administrative Tools -> Services.
  • If any of the above steps doesn’t solve the problem, try a system restart.


Darius Dumitrescu is a creative Senior CMS Consultant with in depth .NET knowledge, focused on Web Development and Architecture Design.

There are no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

View Comments (0) ...