Continually Improving.... let us know how support@devdiamond.net Sign in | Sign up
home articles news blog forum  

 
 


 
Skip Navigation LinksHome > Article > Database Basics :: How to connect to Access database without a DSN (DSN-Less Connection)
Database Basics :: How to connect to Access database without a DSN (DSN-Less Connection)
Abstract :
How to connect to an Access database without need of system resecures.

Views : 7245
Published : Monday, January 21, 2002
By
HyperLink

Avarage Rating :
Page Page 1 of 1


Here is what the code looks like:

Dim oConn, sConnString
Set oConn = Server.CreateObject("ADODB.Connection")
sConnString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & Server.MapPath("\DatabasePath\dbname.mdb") & ";"
oConn.Open(sConnString)



At this point you can define a SQL statement and execute it:

sql = "select * from myTable"
Set RS = Conn.Execute(sql)


The components of the DSN-Less connection explained:

First we instantiate the Connection Object:

Set Conn = Server.CreateObject("ADODB.Connection")


Next we define the actual connection string:

sConnString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & Server.MapPath("\DatabasePath\dbname.mdb") & ";"


Make sure the above line of code is all on one line in your code, don't wrap it. In this statement we are telling ADO (Active Data Objects) that we want to use the MS Access driver and where our database is physically located.

Conn.Open(MyConnStr)

This is the line of code that actually opens the connection to the database. After you have done this you are ready to execute a SQL statement.


About Author

        Yasir Send Feedback
        Yasir is a .NET expert, with over 5 years experience in Microsoft Technologies, 8 years overall programming experience, he is the owner, founder & primary contributor of Minwar.com, and he also works as IT Director in the hospitality industry.