A Nerd's False Positive.

Build database connectionstring easily

No doubt! This article belongs to stone-age era. There is a reason why I walk to the same ancestor era.

Last few week, I’s interviewing techies for the post of .net developer. Before that; I always love to take interviews. First things, it gives you an idea where you are and where they are; a kind of self-analysis. Second, I’m eager to analyze how much passionate they are, in writing codes, other than working just for money.

Surprisingly, I always throw questions that sounds too childish. And, one such question was – “What is the ConnectionString for Sql Server?” Ya! The question sounds too simple. But, I’s shocked and surprised to hear answers from candidates with fairly good amount of experience.

“Oh! That’s easy. You can do that by simply calling Connect() method. The framework will do the rest for you…You don’t need to worry about ConnectionString….”

“In our company, the ConnectionString is encrypted. So, I don’t have a chance to look at it…!”

”We use SqlDataSource. It’ll generate ConnectionString automatically for Us. We don’t need to bother about it…”

Thus, the story goes on.

In fact, it not so easy to remember the lengthy ConnectionString for connecting to all the Database. But, there is a quck and easy method for building a ConnectionString – using a .udl file (Microsoft Data Link).

I’ll show a quick method to create ConnectionString for Sql Server:

  1. Create a text file (.txt extension)
  2. Rename the extension to .udl
  3. Double-click and open the .udl file
  4. From the first tab Provider, select your OleDb provider - Sql Server here and click Next

  5. Now, from the second tab, Connection 


    (a) choose the Sql Server Instance name
    (b) choose Authentication type (Windows/Sql) and
    (c) choose target Database
  6. Click Test Connection. If you connection is correct, you’ll get a success message like


    and hit Ok.
  7. Now, open the .udl file in Notepad.


Hurray! you have the ConnectionString to the Sql Server.

Note: The above ConnectionString is for OleDb data provider. When using in .NET Framework (ADO.NET), remove the section Provider=SQLOLEDB.1.

I guess, now you know the easiest way to build a ConnectionString. This method can be used for generating ConnectionString for MS Access, Oracle, Firebird database etc.