adv banner
Web Programming  Home Web Programming ASP Database Connection Strings
rss

Database Connection Strings

Author: Wilfried Schobeiri More by this author


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.


Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

Read/Add comments to "Database Connection Strings"

comments  SprayMaphia August 09, 2005 says:
Database Connection Strings
As a little addition maybe the MySQL connection string would be nice. Set Conn = Server.CreateObject("ADODB.Connection") Conn.Open("DRIVER={MySQL ODBC 3.51 Driver};SERVER=yourserver;USR=username;PWD=password;DATABASE=yourdb;") Hopefully it will help someone Smile Cheers