Hi, noticed a few people are stuck with what connections, so i have a made
a little script that does the work for you, just follow the instructions.
1. Read the code to get a grasp
2. Copy and save the code in a seperate page
3. include the file on the asp page you are opening that need to access a
Database.
4. Read the instruction after the code
-------------------------------------------------
-------------------------------------------------
Start Code
-------------------------------------------------
-------------------------------------------------
<%
@ LANGUAGE="VBSCRIPT"
ENABLESESSIONSTATE = "FALSE"
%>
<%
' To test if we have made a successful connection before including this
' file we use this test. Leave ENABLETEST = "YES" uncommented until
' we have confirmation that we have the right connection variables
' Get confirmation by executing the page in your browser
' Once you get confirmation comment out ENABLETEST = "YES" so that
' ENABLETEST = "NO"
ENABLETEST = "YES"
'ENABLETEST = "No"
'If you are using a database that is passwordprotected comment out
'PASSWORD = "NO" and vice versa
Dim PASSWORD
PASSWORD = "YES"
'PASSWORD = "NO"
'If you are using a database that is password protectted
'Enter the username and password here
'Dont worry about commenting it out, the script does it for you
'if you are using a non password protected db
Dim CONNUSERNAME,CONNPASSWORD
CONNUSERNAME = "Admin"
CONNPASSWORD = "addbook"
' Enter the path to your database below
Dim DATAPATH
DATAPATH = "C:\Inetpub\wwwroot\admin\addbook\dbzz\addbook.mdb"
DIM ACCESSNEW,ACCESSOLD
'Here is an important part, are you using access2000 or access97
'ACCEESNEW = Access 2000 and ACCESSOLD = Access 97
'If you are using access 2000 comment out the access 97 string
'which is ACCESSOLD and vice versa
ACCESSNEW = "TRUE"
'ACCESSOLD = "TRUE"
'You dont need to edit anything else unless you want to chage the
'variables for your connection
'In that case, read instruction 5 at the end of this code
'-------------------------------
' Decide what DBCONN is going to be so we can select
'-------------------------------
If ACCESSNEW = "TRUE" AND PASSWORD = "YES" Then
DBCONN = "ONE"
End If
If ACCESSNEW = "TRUE" AND PASSWORD = "NO" Then
DBCONN = "TWO"
End IF
If ACCESSOLD = "TRUE" AND PASSWORD = "YES" Then
DBCONN = "THREE"
End If
If ACCESSOLD = "TRUE" AND PASSWORD = "NO" Then
DBCONN = "FOUR"
End If
Sub CONNECTION
Select Case DBCONN
Case "ONE"
Set ADDBOOKR = Server.CreateObject("ADODB.Recordset")
Set ADDBOOK = Server.CreateObject("ADODB.Connection")
ADDBOOK.Open "DRIVER={Microsoft Access Driver
(*.mdb)};DBQ=" & DATAPATH & ";UID=" & CONNUSERNAME & ";PWD=" & CONNPASSWORD
Case "TWO"
Set ADDBOOKR = Server.CreateObject("ADODB.Recordset")
Set ADDBOOK = Server.CreateObject("ADODB.Connection")
ADDBOOK.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" & DATAPATH & ";"
Case "THREE"
Set ADDBOOKR = Server.CreateObject("ADODB.Recordset")
Set ADDBOOK = Server.CreateObject("ADODB.Connection")
ADDBOOK.Open "DBQ=" & DATAPATH & ";Driver={Microsoft
Access Driver (*.mdb)};UID=" & CONNUSERNAME & ";PASSWORD=" & CONNPASSWORD
CASE "FOUR"
Set ADDBOOKR = Server.CreateObject("ADODB.Recordset")
Set ADDBOOK = Server.CreateObject("ADODB.Connection")
ADDBOOK.Open "DRIVER={Microsoft Access Driver
(*.mdb)};DBQ=" & DATAPATH
End Select
End Sub
%>
<%
' Testing part
If ENABLETEST = "YES" Then
CALL CONNECTION
Response.Write "If you you do not see any errors and only this message,
the connection has worked. "
Response.Write "If you get errors make sure you only have 1 database un-
commented and have the "
Response.Write "Variable PASSWORD uncommented once also. Make sure you
have the right db type , "
Response.Write "Access 2000( Accessnew) or Access 97( Accessold). Make
sure you have the right "
Response.Write "path to your db( DATAPATH) and MAKE SURE you have the
PASSWORD variable commented "
Response.Write "accordingly to whether or not your db is password
protected"
Response.Write "<br>Your dbconn type in this script was " & DBCONN
End If
%>
---------------------------
END CODE
---------------------------
Instruction 5
If you want to use different variables for the connection, e.g i used
ADDBOOK for the db connection and ADDBOOKR for the recordset
---------
The access 2000 string with no password used as example
---------
Set ADDBOOKR = Server.CreateObject("ADODB.Recordset")
Set ADDBOOK = Server.CreateObject("ADODB.Connection")
ADDBOOK.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DATAPATH
& ";"
--
You can change it to whatever you want eg. rs for records and MyConn for
connection
---------
The access 2000 string with no password used as example
---------
Set rs = Server.CreateObject("ADODB.Recordset")
Set MyConn= Server.CreateObject("ADODB.Connection")
MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DATAPATH
& ";"
-------
Make sure you change all the connections to reflect your change
--
Some additional information-------
When using the test feature the script prints out information at the end
(as long as there are no errors)
It tells you what type of connection you are using. Heres the key
1. Access 2000 db and password protected
2. Access 2000 db and no pass protection
3. Access 97db with pass protection
4. Access 97db with no pass protection
It will print in the form
Your DBconn type is this script is (and then a number from 1 - 4)
This just tells you additional information, something you already know,
just incase you got lucky :)
If the script doesnt work for you, then you are uncommenting/commenting
the wrong things. There is a small help section in the script at the end.
Its written between the Response.Write commands.
Please give feedback to me on this script, it is greatly appreciated.
Email me at kumars@i... and give me your comments, i doubt they will
let you post them here.
Thanks for listening
Sunil Kumar