Introduction

The following procedure explains how to easily get a SQL Server database connection string from Visual Studio.

Before beginning to learn this, you should know the following details of SQL Server.

Step 1. Open Visual Studio.

Step 2. Go to "View" -> "Server Explorer" as shown in the following

Find-Connection-String-from-Visual-Studio1.jpg

Step 3. Right-click on "Data Connections" and select "Add Connection" or click on the "Connect to Database" icon.

Find-Connection-String-from-Visual-Studio2.jpg

Step 4. You will get an "Add connection" window. In that window, use the following procedure

Step 5. Click on the "Test Connection" button. If you have submitted the correct credentials, then you will get the "Test connection succeeded" confirmation message as follows

Find-Connection-String-from-Visual-Studio4.jpg

Step 6. Now your connection is working successfully, so, now click on the "Ok" button. You will get one data connection under "Data Connections".

Step 7. Right-click on your connection and select "Properties".

Find-Connection-String-from-Visual-Studio5.jpg

You will get the Properties window for your connection. Find the "Connection String" property and select the "connection string".

Find-Connection-String-from-Visual-Studio6.jpg

So now your connection string is in your hands; you can use it anywhere you want.