Sunday, April 20, 2008

An easy way to build connection string.

Though this in not related to .NET directly but it is useful while working with ADO.NET
1) Open a New notepad and save it with "udl" extension, suppose "New.udl".
2) Now you will see that it's icon is changed.
3) Open it, you will find Data Link properties dialog box.
4) For SQl Server connection string select Microsoft OLE DB Provider For SQL Server in Provider Tab.
5) Click button "Next" or select Connection Tab
6) Here you can select all connection details and press button
Test Connection. If it is successful close this dialog box.
7) Now open this file using "Notepad", you will find the connection string. Though it is built for OLE DB
type of connection, you can use for SQL Server connection by removing Provider attribute.
NOTE: If you are using SQL Authentication with password, then check the checkbox Allow Saving Password.
This is necessary so that password appears in connection string.