Database connection string is simply a string variable containing all the detail for a database to which our application deals with. Connection string should be in proper format. It is always a good practice to get the connection string from a UDL file. UDL file is nothing but a text file which contains all the database information as a connection string in it. Interestingly it’s very easy to setup an UDL file and get the required connection string from that. Let’s see how to create the UDL file and get the connection string from it.
Step 1: Create a blank text file (RunàNotepad) notepad and save it by providing any name with an extension *.UDL. Let’s name it as “Conn.UDL”. Before that please ensure the Save as Type should be kept as “All Files”, else the file will be saved as Conn.UDL.txt.
Step 2: Now close the blank text file and go to the Conn.UDL file. Now you can check the icon for the file. Double click on the file and you can see a window named “Data linked properties”. Go to the first tab, I mean the provider tab. There we can find number of OLE DB providers. Choose the suitable provider that we want. Let’s select “Microsoft OLE DB provider for SQL Server” as my application connects to the SQL server database. Then Click “Next>>” button, that will take us to the connection tab. There we need to select or provide a server name. Now choose the types of authentication that we are going to use. If we provide UserID and Password, then we need to check the “Allow Saving Password check box”. Then select the database from the server that we select. After the things are completed, click on the “Test Connection” button. We will get a message as Test connection succeeded.
Step 3: Now we are ready with the connection string. Now close the window and right click on the Conn.UDL file. Open the file with Notepad. Now we are having the required connection string.