PDA

View Full Version : Access Database Connection Issues


JustinW
02-15-2005, 08:16 PM
Hey! I have a client that requires I connect using his Access 2000 Database in a server environment that will not allow me to set it up in his system ODBC which leaves me with the manual connection in asp. I am not unfamiliar with this but I am having some issues this time around. I found a similar problem in this forum but it did not help at all. :confused:


Dim adoCon
Dim rsProducts
Dim strSQL

strSQL = "SELECT * FROM Products ORDER BY ProdName;"

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database.mdb")

adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("database.mdb")

rsProducts.Open strSQL, adoCon

I tried the two adoCon.Open strings seperate mind you. Both gave me the same error which is:

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/whitaker/prodlist.asp, line 10

Thanks!
-Just :cool:

oracleguy
02-16-2005, 03:44 AM
Which was line 10? Was it the line where you opened the connection or the recordset?

And I assume you didnt have both connection lines run right? You commented one of them out when you actually ran the page, correct?

miranda
02-16-2005, 04:43 AM
You are trying to use a recordset object but haven't declared it or opened it.
Dim adoCon
Dim rsProducts
Dim strSQL

strSQL = "SELECT * FROM Products ORDER BY ProdName;"

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

adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("database.mdb")
Set rsProducts = Server.CreateObject("AODDB.Recordset")
rsProducts.Open strSQL, adoCon


To do this without the recordset object just use the execute method of the connection object Dim adoCon
Dim rsProducts
Dim strSQL

strSQL = "SELECT * FROM Products ORDER BY ProdName;"

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database.mdb")


rsProducts = adoCon.Execute(strSQL)


By the way you can use either connection string I have just deleted one in each example so as not to confuse you.

gwendaal
02-16-2005, 06:21 AM
http://www.connectionstrings.com/

JustinW
02-16-2005, 06:18 PM
Miranda, Thanks! I guess I had the whole thing going in the wrong direction in my head. :rolleyes:

miranda
02-16-2005, 07:09 PM
You are welcome. I am glad that I could help.

oracleguy
02-17-2005, 01:51 AM
I saw that and thought that might be the problem but I didn't say anything because you didn't say which line specifically the error was occuring on so it could have been something else. Just a tip in the future, even though the error says the line number, it is meaningless when you only paste the problematic block in. So say or highlight which line the error message is talking about.