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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADODB.Command Using Microsoft JET 4.0 Provider just will not execute.

Status
Not open for further replies.

Jables

Programmer
Aug 28, 2001
148
US
Can anyone tell me why this code:

Code:
set oConn = Server.CreateObject("ADODB.Connection")
DBPATH = Server.MapPath("/") & "\subdir\dbasename.mdb;"
keyarch_noDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPATH & "Persist Security Info=False"
oConn.Open(keyarch_noDSN)

strSQL = "INSERT INTO tblUser (Username,Password) VALUES ('clay','pass')"

Set cmdTest = Server.CreateObject("ADODB.Command")
cmdTest.ActiveConnection = oConn
cmdTest.CommandText = strSQL
cmdTest.Execute
cmdTest.ActiveConnection.Close

Set cmdTest = Nothing
Set oConn = Nothing

Keeps producing the error:

Code:
Microsoft JET Database Engine error '80040e14' 

Syntax error in INSERT INTO statement. 

/debug.asp, line 14

The SQL statement works just fine in my local copy of the database, but it just will not work when I run it against the database on the remote server.
 
Have you tried:
Code:
strSQL = "INSERT INTO tblUser (Username,Password) VALUES ('clay','pass');"
Tiny difference I know. Just a semicolon at the end.
 
Response.Write DBPATH
Response.End

See if that location is the real location of your DB file.
 
Baddos,

I have tried your suggestion, but to no avail. The DBPATH variable is pointing to the correct location. I have been able to retrieve records from the database using this method, but I just can't seem to get the INSERT INTO statement to work.

Dillettante,

I haven't tried your suggestion yet, but I will.

I am starting to think it may be a problem of the connection string or the connection type. I have used this method to add records before, but it was using a DSN and not a DSN-less connection string. I'm wondering if I need to open an ADODB.Recordset and use the .AddNew, .Update method to add records. If this doesn't work, then I suspect that the webhost doesn't have the correct permissions set on the directory that holds the database, although I have checked with them and they assure me the permissions are correct.
 
Rather than use the command object, use the excute method of the connection object:

Code:
oConn.Execute(strSQL)

--James
 
I think you'll find 'Password' is a reserved name in access databases. Try changing the field name to something else.

Hope this helps.

--------------------------------
If it ain't broke, don't fix it!
 
Or add delimiters to the fieldnames:

Code:
strSQL = "INSERT INTO tblUser ([Username],[Password]) VALUES ('clay','pass')"

--James
 
Using the same method to connect to the database as in my initial post, this is what I ended up using:

Code:
'Open a recordset for inserting new client record
Set RS = Server.CreateObject("ADODB.Recordset")
RS.ActiveConnection = oConn
RS.Source = "SELECT * FROM tblUser"
RS.CursorType=3
RS.CursorLocation=2
RS.LockType=3
RS.Open()

'Update the database with form values
RS.AddNew FieldList, FieldValues
RS.Update
RS.Close

Code:
FieldList
and
Code:
FieldValues
are each arrays containing the contents they describe. Oddly, I didn't have to change the name of the field,
Code:
Password
, and I actually had to remove the delimiters from the field names in order for this to execute correctly. Thanks everyone for the helpful suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top