Book Store  
  Contact Us  
  Links  
  Site Map  
ASP Scripts - database connections

Using .udl files to construct ASP database connection strings

 

When developing ASP / database applications you will have to create connections strings for ADO. These can get quite complex and if you are working with different databases it can be difficult to remember the format.

The kind of connection string you may be creating will look something like this :

Provider=MSDASQL.1;Persist Security Info=False;User ID=username;Data Source=server1

A useful utility to help create complex database connection strings is available through the .udl file. The connection strings can be created and easily tested using the facility.

Method

Open up NotePad or a similar text editor and create a new blank file then save it with a .udl extension. Call it connect.udl for example. In Windows Explorer Right-click on the file name and select 'Open'. You will then be presented with the datalink properties.

connection

First select the Provider tab and from the list select the appropriate OLEDB provider. The ones I use the most are 'Microsoft OLE DB Provider for SQL Server' (for SQL Server) and 'Microsoft Jet 4.0 OLE DB Provider' (for MS Access).

Click on Next and you will be presented with the 'Connection' tab which will have edit boxes for the chosen Provider.

In the case of SQL Server, first enter the server name. This will usually be the IP address of the server. If you are using a specific user name and password, enter the details into the edit boxes and don't forget to press 'Add Saving Password'. You should then be able to Select the database on the server from the drop down list.

If the database does not appear in the drop down list, then you are not connected to the SQL Server or you have entered the wrong IP address.

In the case of MS Access, you have to enter in the location of the database which is the directory and file name.

Once you have filled in the details press OK.

Now you can go back to Windows Explorer, right click on the file name and select Open with Notepad. This is give you the connection string which you can just copy and paste into you .net aapplication.