Get Connection String From Visual Studio 2017 “Server Explorer”

Mostly, developers need to build their string when need to get the ConnectoinString to connect database. Instead, we introduce another approach using the Server Explore in newer version Visual Studio.

To get the connection string, we need to add the database in our Server Explorer. Click “View” in the Visual Studio main menu, then click the “Server Explorer”.

Now, right click the “Data Connections”, choose “Add Connections”. Then you can specify the data source type you want. Just like the pop up below.

In my case, it is just my local SQL Server, I choose “Microsoft SQL Server”. After choosing the data source type, you may now get the Server Setting pop up. You need to type in the “Server Name” if the Dropdown could not help to find your database.

After choosing the Server Name, you may specify the Database Name. Then click ok button.

If there is no error message pops up, the connection should be good in you Server Explorer. Check your Server Explorer and find your connection.

Now, right click your connection and click “Properties”, check the Properties Section in the right bottom of your Visual Studio.

In the Connection String part, you could get and use the Connection String.

The benefit of using this approach is we get the connection first from Visual Studio. Since we could get the database connection already, we are sure the connection will be good in your application usage. And the connection is copied from Visual Studio, we are more confident about the correctness. However, you maybe still need to modify your connection string in your own case, like the data file size if you using compact data file.

Leave a reply:

Your email address will not be published.

Site Footer