Link to home
Start Free TrialLog in
Avatar of JasLane
JasLane

asked on

Adding record errors

I am having difficulty with some asp where I am trying to add a record to a database.

My errors come on two levels:

(1) If I use OPTION EXPLICIT I get "Variable is undefined: 'adModeReadWrite' ",
and
(2) If I don't use OPTION EXPLICIT I get "ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another." from line ** instead.

Here's my problem code:

      Dim Conn, RS, DSNName, sql
      Set Conn = Server.CreateObject ("ADODB.Connection")
      Conn.Mode = adModeReadWrite
      DSNName = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
      DSNName = DSNName & Server.MapPath("/Dbimages.mdb")
      Conn.Open DSNName
      Set RS = Server.CreateObject("ADODB.Recordset")
      sql = "SELECT * from Images"
**      RS.Open sql, Conn, adOpenStatic, adLockPessimistic

      RS.AddNew
      RS.Fields ("Filename") = Request.Form("UpFile")
      RS.Fields ("Category") = Request.Form("UpCat") etc. adding more fields to a database from a form...
SOLUTION
Avatar of c_swanky
c_swanky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of c_swanky
c_swanky

For Item (1) You can do ONE of the three things I have listed there.....
Alternatively to including the adovbs file in every ASP page, you can edit your global.asa file and place the following:

<!--METADATA TYPE="typelib" FILE="C:\program files\common files\system\ado\msado15.dll" -->

This will automatically load all of the VBS constants for you when your application is loaded.

Hope this helps!
Have you included adovbs.inc in your code..
Avatar of JasLane

ASKER

Sorry no reply for a while - modem probs!

To answer your Q Sairam, no I haven't included adovbs.inc yet because I'm a bit of a newbie and don't know what it is?? what is "adovbs.inc" and where can I find it to include it?

I'm in the process of trying Swanky's ideas so I'll get back to you all soon..
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JasLane

ASKER

R,

thanks for the help. I'm past the earlier problems with your code snippet above but now I'm getting another error. "Microsoft OLE DB Provider for ODBC Drivers (0x80004005) [Microsoft][ODBC Microsoft Access Driver] Cannot update. Database or object is read-only." (The error is coming on the RS.Update line).

I'm using MS Access 2002. How do I change my db properties or is there another VB problem with this line in my asp page?

      Conn.Mode = adModeReadWrite

Appreciate your help and you were on the right track Swanky (with the const dim)!!

I haven't included the "adovbs.inc" in the code yet as I'd need to change the path for the hosting server (eg. server.MapPath & ..) and am trying to keep it simple as I'm still learning my way..
Jas,

When I open my recordsets for writing, I generally do so as follows:

DIM RS
SET RS = server.createobject("ADODB.Recordset")

RS.open SQLStatement, ObjConnection, adOpenKeyset, adLockOptimistic

I use the Keyset option because I have had consistent success with adding a record, calling the update method, and then being able to reference the ID of the new record (Great for multi-tabled apps)

If this does not work, check the permissions on the database file itself. Remember that the IUSR Win2K/NT account needs to have modify access to the database for it to function properly.

Let me know if this helps or if you run into any other problems!

R-
Avatar of JasLane

ASKER

R-,

I've changed my RS.Open line to read like yours but I'm getting the same error as before (Object or database is read only). I went in to the ODBC sources and checked that my dbImages database (listed as a System DSN) did not have "Read Only" ticked - all OK there.  

I'll check Windows help to see if I've missed something unless you know what I've done wrong here?

Maybe I've got a conflict between DSN-less connection and having it listed in my data sources on my local computer?

Jas
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JasLane

ASKER

R-,

You are a legend! The IUSR_MACHINENAME was added and now it all works fine. Thanks for the permission and adovbs tips along the way.

Only other problem is now I'm getting blank records in the database. It would appear the form "post" is not working. I have all text fields and one file field so I'm using "multipart/form-data" in the form tag. I'm sending from add_record.asp to add_record_update.asp but on the new page the Response.Form("NFile, etc") are all blank.

My code in "add_record.asp" page:

<Form action="Add_record_update.asp" method="post" enctype="multipart/form-data">
<div align="center"><br>Add record to Images database</div>
<br>
<p>File:<br><input name="NFile" type="file"></p>
<p>Volume:<br><input name="NCat" type="text"></p>
<p>Film:<br><input name="NSub" type="text"></p> .. etc ..
</Form>

Then in "add_record_upload.asp" we have:

      Set RS = Server.CreateObject("ADODB.Recordset")
      sql = "SELECT * from Images"
      RS.Open sql, Conn, adOpenKeyset, adLockOptimistic

      RS.AddNew
      RS.Fields ("Filename") = Request.Form("NFile")
      RS.Fields ("Category") = Request.Form("NCat")
      RS.Fields ("Subcat") = Request.Form("NSub")
      RS.Fields ("Title") = Request.Form("NTit")
      RS.Fields ("Caption") = Request.Form("NCap")
      RS.Update
      RS.Close

Any advice you can give on this?
Yes, but before I can answer I need to ask you a question. Are you intending to save the file to disk or are you just looking to save the information stored in the NFile field?

From your statement about using multipart "enctype="multipart/form-data"" it sounds like that is your intention.

How are you accomplishing your upload and saving the file to disk? I personally use an upload class that I found (I can't even remember where anymore and it wasn't commented at all) so for me, using your code, I would call my upload class as follows:

SET objFile = NEW Uploader
'some additional code here for the uploader functions

 Set RS = Server.CreateObject("ADODB.Recordset")
     sql = "SELECT * from Images"
     RS.Open sql, Conn, adOpenKeyset, adLockOptimistic

     RS.AddNew
     RS.Fields ("Filename") = objFile .Form("NFile")
     RS.Fields ("Category") = objFile .Form("NCat")
     RS.Fields ("Subcat") = objFile .Form("NSub")
     RS.Fields ("Title") = objFile .Form("NTit")
     RS.Fields ("Caption") = objFile .Form("NCap")
     RS.Update
     RS.Close

Does this help at all? If not give me some more info about the intentions of the form and whether or not you are saving the file to disk, and if so, how you are accomplishing that. From there I can get a better idea of where to steer you :-)

R-
Another thing I wanted to mention about that adovbs.inc file. If you do choose to use it, copy it from it's default location and place it in a directory somewhere on your site.

Also, rename the extension .asp so the user will not get a download dialog should someone happen upon your file.

R-
Avatar of JasLane

ASKER

Yes R-,

thanks for the tips on the upload class (and changing the .ext on adovbs).

With your help, things are set up correctly now (pretty much as you've posted above). The images are being uploaded and the records updated!

Jas