ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!



Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

QUICK TIP:
Server-Side vs. Client-Side Scripting
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Accessing a Password Protected Access DB

While using a database level password on an Access database is by no means the best security, it will prevent the casual user from being able to open the file. Unfortunately this password is set at the Access level and, as such, the password you normally provide in your ADO connection string won't get you past it. So the question becomes, if you want to password protect your mdb file, how can you continue to query your data via ASP?

Luckily it's pretty easy even though it's not obvious. It's done by using a provider-specific attribute called Jet OLEDB:Database Password and you need to specify it when or before you call the .Open method of the ADO connection object.

<%
' Declare our variables
Dim cnnPasswordTest
' Create our ADO Connection object
Set cnnPasswordTest = Server.CreateObject("ADODB.Connection")
' Before we can set a provider-specific attribute we need to
' indicate what provider we'll be using.
cnnPasswordTest.Provider = "Microsoft.Jet.OLEDB.4.0;"
' Set the Jet OLEDB provider-specific Database Password property
' to the Access password you set from within Access.
cnnPasswordTest.Properties("Jet OLEDB:Database Password") = "dbpass"
' Now we can proceed to open the database connection as usual
' except for the fact that you leave out the provider because
' it was previously set above.
cnnPasswordTest.Open "Data Source=C:\path\filename.mdb;"
' Do your database stuff here as you normally would.
' Closing and clearing the objects is always a good idea.
cnnPasswordTest.Close
Set cnnPasswordTest = Nothing
%>

If you find it easier, it's also possible to simply include the property in your connection string like this:

<%
' Declare our variables
Dim cnnPasswordTest
' Create our ADO Connection object
Set cnnPasswordTest = Server.CreateObject("ADODB.Connection")
' Open our connection as usual except we need to add the Access
' Jet OLEDB provider-specific Database Password property and
' set it equal to the value of the Access password you set
' from within Access.
cnnPasswordTest.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
	& "Data Source=C:\path\filename.mdb;" _
	& "Jet OLEDB:Database Password=dbpass;"
' Do your database stuff here as you normally would.
' Closing and clearing the objects is always a good idea.
cnnPasswordTest.Close
Set cnnPasswordTest = Nothing
%>

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers