C# - Finding connection string - Easy way

Most of the times we used to face difficulty while creating connection strings in our C# applications and especially when you are working in data intensive apps.

I used to do lots of permutations and combinations (due to drivers installed) to find out the proper connection string in my initial career. Here I would like to explain easiest way and proper manner to test the connection ahead to actual usage.

For database connections in C# apps you often need to supply an ADO Connection String. Here is a tip how to generate such string very easily.

(Windows only)

  1. Go to your desktop 
  2. Right click and choose NEW/Microsoft Data Link - if you don't have this option on your menu, just choose NEW/Text Document 
  3. If you have make a new text file - change the file extension from .txt to .udl 
  4. Double click on the new file - you will see now the Microsoft Connection wizard (Data Link Properties) 
  5. Choose your database driver and connection properties 
  6. Test the connection 
  7. Choose OK to save the file 
  8. Now click on the Start Menu (button) and choose Run... 
  9. Type WRITE (or Notepad) 
  10. Drag the file from your desktop just behind the command that you type on step 9 - you will see the file name and path appear just after WRITE 
  11. Run the command - you will see now the text editor started with your connection file open in it. It is all text 
  12. Select and copy the line after the comment "; Everything after this line is ..." 
  13. This you your ADO connection string! You can use this in your APP now! Just paste it into wherever connection dialog/string is asked for. 

The same way you can do all the connection’s with OLEDB. I used to do same with Access/Excel files as well.

This is all because of Microsoft Connection wizard (Data Link Properties).

BTW, UDL stands for universal data links. In the wizard you can see all the drivers installed or supported in your machine.

That's it - have fun!

Comments

Popular posts from this blog

Download file using WCF REST services

server side printing / PDF conversions using c# and asp.net/wcf service

Finding file size in bytes on serverside using c#