Web Site Creator Web Hosting Help
   Using SQL/Access with ADO


How to access SQL Server from ASP

If you have a SQL Server account with us, it is very easy to access your database from ASP. Here is sample code for establishing a connection

Dim objDbConn

' Create the ADODB Connection object
Set objDbConn = Server.CreateObject( "ADODB.Connection" )

' Connect to the DB
objDbConn.Open( "DSN=UserDBconn;UID=youraccountname;PWD=yourpassword" )


That's all there is to it. Notice the DSN is named "UserDBconn" and the UID is your account name and PWD is your password.

How to access an MS Access database from ASP

Every one of our web sites can utilize an MS Access database. You must create the database and upload it to your /Db directory. This is very important- it will not function correctly from any other directory. The /Db directory has special write access that lets you update your database. Here is sample code for establishing a connection to the database:

Dim objDbConn
Set objDbConn = Server.CreateObject("ADODB.Connection")
objDbConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\youraccountname\db\MyDbName.mdb")


Make sure you specify the path correctly - including the name of your .mdb file (called "MyDbName.mdb" above).

Executing a SQL statement

Here is some sample code, utilizing the above connection, that executes a SQL statement on a table:

Dim objRs

' Run the query
Set objRs = objDbConn.Execute( "SELECT MyColumn FROM ExampleTable" )

' Print out all the records
While Not objRs.EOF
Response.Write( objRs( "MyColumn" ) & "<br>" )

' Move to the next record
objRs.MoveNext
Wend

Sign Up Now! Overview

Questions? Call sales at
1 (425) 274-4500
Or try our
Visit our Help Center where you can get simple and quick product support.
   is an affiliate of   , a leading domain name services company.
Copyright © 1998-2018 Enom LLC. All rights reserved. Terms & Conditions | Privacy Policy | Abuse Policy