ASP – An open application environment, it enables powerful server-side scripting.  Home Web Programming ASP Database Connection Strings
Your Ad Here

Database Connection Strings


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.


Author's URL: Wilfried Schobeiri
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More ASP Tutorials at LearnPHP.org

Add comments to "Database Connection Strings"

Only registered users can write comment

Reader's comments
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 :)

Cheers