Click here to Skip to main content
15,867,453 members
Articles / Database Development
Tip/Trick

Using Visual Studio to find a database connection string

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
14 Jan 2012CPOL1 min read 66.8K   2   2
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)


Written By
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?

Comments and Discussions

 
QuestionQuestion Pin
Serbeer14-Jun-12 5:46
Serbeer14-Jun-12 5:46 
AnswerRe: Question Pin
OriginalGriff14-Jun-12 6:00
mveOriginalGriff14-Jun-12 6:00 

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

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