Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Databases, why oh why won't this work??

Status
Not open for further replies.

HotMadras

Programmer
Apr 20, 2001
74
GB
I'm at the end of my tether here. This is driving me nuts. I have a database that I need to connect to and I'm using the code below to do it, but for some reason it ain't working. The exact same code (split up into chunks and wrapped around some html and other stuff) works perfectly in another page, but it simply refuses to work here. Any clues? Currently it's only supposed to look at the first record, but it will eventually be modified to look at any record. It's so simple I can't see what I've done wrong. Anyway, here it is:
Code:
        Dim dbc
	Dim strConn
	Dim rs
	Dim strpath
	strConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ="& server.mappath("database/indespension.mdb")
	Set dbc = Server.CreateObject("ADODB.Connection")
	dbc.open strConn
	

	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.Open "parts", dbc
	rs.movefirst
	
	aParameters = Array(rs("partno"), "test", "test")
	rs.Close
	dbc.Close
 
I rewritten your code below:

Dim dbc
Dim strConn
Dim rs
Dim strpath
strConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ="& server.mappath("database/indespension.mdb")
Set dbc = Server.CreateObject("ADODB.Connection")
dbc.ConnectionString = strConn
dbc.open

Set rs = Server.CreateObject("ADODB.Recordset")

rs.CursorType = 3 'adOpenStatic
rs.LockType = 1 'adLockReadOnly
rs.ActiveConnection = conn
rs.Open "parts"



if rs.BOF and rs.EOF then
Response.Write("Recorset empty")
else
rs.MoveFirst
While not rs.EOF
'do something
rs.MoveNext
Wend
end if


aParameters = Array(rs("partno").Value, "test", "test")
rs.Close
dbc.Close


'Deallocate servers's memory
set rs=Nothing
set dbc=nothing


As you can see I made the following modifications:
- I passed the connection string to the ConnectionString property instead of the conn.open method
- I passed the connection object to the ActveConnection property instead of the rs.open method
- I added the LockType adn CursorType propeties to recordsets

But I think you got error from the line with the Array(...

I am always using these kind of schema and I never got problems like yours. The trick is to avoid to pass arguments to the methods but to pass the in the properties before calling the method.

If you still have problems, let me know,

Hope this helps,


s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top