Click here to Skip to main content
12,999,653 members (41,396 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 14 Jan 2012

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


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


About the Author

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?

You may also be interested in...


Comments and Discussions

QuestionQuestion Pin
Serbeer14-Jun-12 5:46
memberSerbeer14-Jun-12 5:46 
AnswerRe: Question Pin
OriginalGriff14-Jun-12 6:00
mvpOriginalGriff14-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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 14 Jan 2012
Article Copyright 2012 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid