Get SQL Server Database Connection String Easily From Visual Studio

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

  1. Before beginning to learn this you should know the following details of SQL Server.
     
    • Server Name
    • Username
    • Password
    • Database name that you want to connect to
       
  2. Open Visual Studio.
  3. Go to "View" -> "Server Explorer" as shown in the following:

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

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

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

  5. You will get an "Add connection" window. In that window use the following procedure:
     
    • Provide "Server name"
    • Select the "Use SQL Server Authentication" radio button.  Then submit the Username and password.
    • If you enter the correct details then you can select the database you want to connect to from the "Select or enter a database name" dropdown list.

      Find-Connection-String-from-Visual-Studio3.jpg
       
  6. 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

  7. Now your connection is working successfully; so, now click on the "Ok" button. You will get one data connection under "Data Connections".
  8. Right-click on your connection and select "Properties".

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

  9. 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

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