You are Here: FAQScripting & ProgrammingASPArticle #7
How do I make a connection to Access Database using ASP?
Microsoft Packages Only!
In this guide, we already have a Microsoft Access database created named salesDB.mdb which has been uploaded to an MS Hosting package in the db/ folder. Within this Access database there is one table named tbl_Sales. This table holds the data for recent sales by employees. Look below at the data in the database.
In this example, we will create an ASP script in VBScript to connect to the Access database, print the price for each sale on the page as well as the total for all sales.
The VBScript example above is saved to the root of the webspace. The function Server.Mappath() will output the current folder structure for where the script is saved. The value in parenthesis can be used to specify a file name, subfolder, parent folder, parallel folder, etc. The line
It is very important to close the connection once you are done querying the database. Only then will the memory resources be released. It is always good to have very minimum connections open.
Never under any circumstances use the following method to determine the number of lines received:
The system will have to go through the entire record and all its columns without using any of the data in there. This takes time, the page takes longer to load, and the database connection is open for longer (as already mentioned, there is a limit to the number of connections that can be open at the same time).
To find the number of row in a table, use the following code:
Alternate Connection Scripts
You can replace the sConnStr above to use the Microsoft Access Driver instead if you prefer.
Disclaimer: 1&1 provides the scripts and related information on this page as a courtesy, subject to 1&1's General Terms and Conditions of Service (the "GT&C"). As set forth in more detail in the GT&C, the scripts and information are provided "as-is", without any warranty, and 1&1 is not liable for any damages resulting from your use of the scripts or information.
© 2012 1&1 Internet Ltd