This works extremely well if you are using an MS Access database.

In order to connect to a database, there is a connection string that has to be created. The connection string is done for you automatically with the ODBC Manager. So, when you open a connection in your code, you only specify the name of the DSN for your connection string.

A connection string contains pairings of "setting=value" all separated by a semi-colon. When you set it up in the ODBC Manager, you are specifying the Provider and the Data Source settings. The connection string would look like this:

Provider=Microsoft.Jet.OLEDB.4.0; Data Source=

where  is the path and file name of your database (without the brackets).  In the code from the previous lecture, you would use this string instead of the DSN. So, what we have is a DSN-less connection.

strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\My Documents\CIS237\MyDatabase.mdb"

This works well if you know the path to your database. However, if you are using a web hosting company, they are not going to give you that information. You have to specify a virtual path. What we do in this case is use a different set of properties: Driver and DBQ. Also, the connection string has to be built dynamically in the code because we have to get the virtual path.

strCon = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/cis237") & "\MyDatabase.mdb"

The Server.MapPath is a function that takes a relative path and returns the virtual path. In the example above, I created a subfolder on my website called "cis237" and placed MyDatabase.mdb into it. If you put the database in the root of your website, you would just pass "/" as the argument to the function.

These are the formats I've always used. I don't recall if there is a reason for using the Driver setting in the second example instead of the Provider setting.