Using Visual Studio to find a database connection string

I have to give these instructions quite often in Q&A, so it seemed sensible to write them one more time, and then point people in this direction in future...
One of the things it can be difficult to work out is what you actually need in your connection string to access a database via your code. Although there are sites which give examples, (this[^] is a good one) it would help to have a connection to your database open and working to take it from. Visual Studio can help you there.
1) Open the Server Explorer pane. ("View" menu, "Server Explorer" or CTRL+W, L by default)
2) Open the "Data Connections" list. If your database in on the list, skip to step 3
2.1) On the Server Explorer tool bar, click the "Connect to Database" button (yellow column, with green cross and a plug-and-wire icon)
2.2) On the resulting dialog, select the appropriate Date Source, Server name, and other details until the "Test Connection" button works.
2.3) Press the "OK" button to add the connection - this does not affect your project or solution in any way!
3) Click once on the database to highlight it.
4) Look at the Properties Pane (If it isn't visible - and it should be, at all times - then the "View" menu, "Properties Window" or CTRL+W, P will open it)
5) Near the top will be the property "Connection String". You can right click the value, and use "Select All" and "Copy" to move it to the clipboard, ready to be pasted into you application (or preferably your application config file).

Yorum Gönder

0 Yorumlar

Ad Code

Responsive Advertisement