SEARCH
Newsletter
Subscribe to get design tips, latest trends, free stuff and more.
It doesn't look like an e-mail address

hosting

  Web Programming ASP Database Connection Strings

Database Connection Strings

Wilfried Schobeiri ASP Apr 14, 2005

Database Connection StringsLearn how to connect to different kinds of databases in ASP.

Although our ASP database tutorials all use MS Access connection strings, there are many sorts of database software out there for use with ASP. This tutorial will show you how to connect with them.

MS ACCESS
First, we'll take a look at the regular MS Access Connection String:

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0; DBQ=" _
& Server.Mappath("db/users1.mdb") & "User ID=Administrator;Password=rev01t;"
Conn.Open

Some people have trouble with this string, so I decided to add another connection string in its place:

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.connectionstring = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" _
& Server.Mappath("db/users1.mdb") & ";User Id=Administrator;Password=rev01t;"
Conn.Open

One of these two should work out for you, where the Password is the database password, or a combination of the User ID and the Password are given to restrict access to a certain table. Note: if you have no username or password, erase everything after the third to last ';' like so: & Server.Mappath("db/users1.mdb") & ";"
MS SQL
This is a less common alternative to Access databases, most commonly used by large scale websites. Here's our connectionstring to SQL:

set Conn = server.createobject("ADODB.Connection")
Conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=servername;User ID=username;_
Password=password;DATABASE=databasename;"

There's your MS SQL string. Be sure to change servername to the name of the server (localhost, computername, or IP), and to change username, password, and databasename to match those of your database.

subscribe to newsletter