Click here to Skip to main content
Click here to Skip to main content
Go to top

Using Visual Studio to find a database connection string

, 14 Jan 2012
Rate this:
Please Sign up or sign in to vote.
Visual Studio has a Server Explorer built in to handle database access - it can lalso generate database connection strings ready for saving in application config files.
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).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

OriginalGriff
CEO
Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?
Follow on   Google+

Comments and Discussions

 
QuestionQuestion PinmemberSerbeer14-Jun-12 5:46 
AnswerRe: Question PinmvpOriginalGriff14-Jun-12 6:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 14 Jan 2012
Article Copyright 2012 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid