Simplifying ADO Database Connection Strings
Connecting SCADA systems and other applications to databases have been common for quite some time. SCADA platforms from GE, Rockwell, and Wonderware for instance, require that connection to be made utilizing a connection string. A database connection string is simply a string variable containing all the detail for an application to connect to the database. While there are many different resources which define the format of a connection string, creating one can prove to be frustrating as the syntax needs to be perfect in order to work.
The following steps are a foolproof way to create a connection string utilizing a wizard driven interface right from your Windows desktop utilizing a Microsoft Universal Data Link File (UDL). A 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.
How to Create the UDL File and Get the Database Connection String
Step 1: Create the UDL File
- Create a blank text file using notepad.
- 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: Configure the UDL File
Now close the blank text file and go to the directory containing the conn.UDL file. You will see that the icon has changed as Windows recognizes the file as a universal data link file.
- Double click on the file and you can see a window named “Data linked properties”. On the provider tab we can find several different 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 authentication information and database. Please note that these properties will be different depending on the database provider you are connecting to. 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. Click OK to close the dialog box.
Step 3: Copy the Connection String
Now we are ready with the connection string.
- Right click on the conn.UDL file and open the file with Notepad.
- As is stated in the file – everything after the second line is the connection string which can be copied and pasted into your application.