Click here to Skip to main content
15,884,099 members
Articles / .NET
Tip/Trick

Get DataBase Connection Strings in an Easy Way

Rate me:
Please Sign up or sign in to vote.
4.80/5 (48 votes)
27 Sep 2013CPOL1 min read 114.8K   43   30
Communication with database in .NET is easy but sometimes one gets stuck by wrong format of connection string

Introduction

In computing, a connection string is a string that specifies information about a data source and the means of connecting to it. It is passed in code to an underlying driver or provider in order to initiate the connection. Whilst commonly used for a database connection, the data source could also be a spreadsheet or text file.

The connection string may include attributes such as the name of the driver, server and database, as well as security information such as user name and password (source Wikipedia[^]).

UDL file can be used to generate connection strings easily.

How to make UDL file?

  1. Make a text file, open it.
  2. Click on Save As.
  3. Write filename as something.udl, file type All files, click Save.
  4. Now run something.udl.
  5. Click on Provider tab. Select the provider and click Next.
  6. Give the DataBase Path, Give Username, Password, if any.
  7. Click on Test Connection.

If it's OK, then close it now.

Now open udl file as text file, connection string will be there in the last line.

Following is the connection string format for Oracle:

C#
private static string CONNECTION_STRING =
"User Id=myUserID;Password=myPassword;Data Source=(DESCRIPTION=" +
"(ADDRESS=(PROTOCOL=TCP)(HOST=myserver.server.com)(PORT=yourPort#))" +
"(CONNECT_DATA=(SID=yourSID)));" 

An alternate way of doing it is as follows:

  1. Add DataGridView in your Form.
  2. Provide DataSource by browsing, do the Settings, once all done, don't click OK, go back to the first step by clicking Previous.
  3. Click on Show Connection String.
  4. Copy it, and use where you want.

For more details with screenshots, see MY article Connection Strings[^].

Following are the links to websites which provide Connection Strings Format for various DBMS:

License

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


Written By
Pakistan Pakistan
I am a learner.

Comments and Discussions

 
QuestionI liked it Pin
Shivprasad koirala15-Nov-11 0:30
Shivprasad koirala15-Nov-11 0:30 
Generalnice beginner tip Pin
Simon_Whale24-May-11 6:01
Simon_Whale24-May-11 6:01 
GeneralA handy tip ... Pin
Peter Hayward21-Mar-11 13:24
Peter Hayward21-Mar-11 13:24 
GeneralAnother useless article Pin
damnedyankee24-Feb-11 5:17
damnedyankee24-Feb-11 5:17 
GeneralRe: Another useless article Pin
dontumindit26-Feb-11 21:53
dontumindit26-Feb-11 21:53 

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.