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