Database Problem

Hi there
I am fairly new to ASP, and I am stuck on this very annoying problem I have.

The following code:

<%@ Language=VBSCRIPT %>
<% Option Explicit %>
<!--#include virtual="/HumanR/SPTR/adovbs.inc"-->
<%
     'Open up a connection to our Access database
     'that stores the info about the users
     Dim objConn
     Set objConn = Server.CreateObject("ADODB.Connection")
     objConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" &_
                          "DBQ=" & Server.MapPath("SPTR.mdb")
     objConn.Open
     
     'Read in the characters the user entered
     Dim Uname, Pword, Pword2
     Uname = Trim(Request("Username"))
     Pword = Request("Password")
     Pword2 = Request("Password2")
     If Pword <> Pword2 OR Uname = "" OR Pword = "" OR Pword2 = "" Then
          Response.Write"You have typed in incorrect information, or you have not typed in anything. Please <A HREF='newuser.asp'>Return to the new User Page.</A>"
     Else
          'Create a recordset object instance, and add the entries into the table
          Dim objRS
          Set objRS = Server.CreateObject("ADODB.Recordset")
          objRS.Open "TblUsers", objConn, , adLockOptimistic, adCmdTable
          objRS.AddNew
          objRS("Username") = Uname
          objRS("Password") = Pword
          objRS.Update
          Response.Write"The Username " & Uname & " and password " & pword & " have been added. <A HREF='default.asp'>Click here to go to Login Page.</A>"
     
          'Clean Up our ADO objects
          ObjRS.Close
          Set objRS = Nothing
     End If
     objConn.Close
     Set objConn = Nothing
%>
</BODY>
</HTML>

Creates the following error:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query.

/HumanR/SPTR/useradd.asp, line 28

And I don't know why

Please help

Lewis a.k.a. Yeggstry

yeggstryAsked:
Who is Participating?
 
daveamourConnect With a Mentor Commented:
Thanks
0
 
daveamourCommented:
Try changing this line

objRS.Open "TblUsers", objConn, , adLockOptimistic, adCmdTable
         
To

objRS.Open "TblUsers", objConn, 2, 3, adCmdTable

Dave
         
0
 
shastry_yedavalliCommented:
HTTP access is done via the account IUSR_xxxx account. If this user does not have a write access to the folder or file you get such errors.

You have two solutions.

1. Place the MDB file into cgi-bin directory and try again.
2. If this fails, then create an ODBC connection and establish DB connection via ODBC.

The first solution may not always work. But the second solution is a sure solution and works.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
daveamourCommented:
I shoul dhave explained why this might work.  Its basically what kind of cursor you use.  Some are read only for example.

Check this out

http://www.learnasp.com/learn/adocursortypes.asp

Dave
0
 
LOBOCommented:
Try this code:

<%
function safeforsql(sqlstring)
 do until instr(1,sqlstring,",",1) = 0
  sqlstring= left(sqlstring,instr(1,sqlstring,",",1)-1) & ";" & right (sqlstring,len(sqlstring) - instr(1,sqlstring,",",1))
 loop
 do until instr(1,sqlstring,"'",1) = 0
  sqlstring= left(sqlstring,instr(1,sqlstring,"'",1)-1) & "`" & right (sqlstring,len(sqlstring) - instr(1,sqlstring,"'",1))
 loop
 safeforsql = sqlstring
end function


Dim objConn
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" &_
                         "DBQ=" & Server.MapPath("SPTR.mdb")
    objConn.Open
   


'Read in the characters the user entered
    Dim Uname, Pword, Pword2
    Uname = Trim(Request("Username"))
    Pword = Request("Password")
    Pword2 = Request("Password2")
    If Pword <> Pword2 OR Uname = "" OR Pword = "" OR Pword2 = "" Then
         Response.Write"You have typed in incorrect information, or you have not typed in anything.
Please <A HREF='newuser.asp'>Return to the new User Page.</A>"
   
 <%
 Response.End
else

 sql="INSERT INTO YOUR_TABLES_NAME (YOUR_DATABASE_FIELDS_SEPERATED_BY_A_COMMA)"
 sql=sql & " VALUES ( "
 sql = sql & "'" & safeforsql(Username) & "', "
 sql = sql & "'" & safeforsql(Password) & "') "
 
 
 Set insert = Conn.Execute(SQL)

Response.Write"The Username " & Uname & " and password " & pword & " have been added. <A HREF='default.asp'>Click
here to go to Login Page.</A>"
   
         'Clean Up our ADO objects
         ObjRS.Close
         Set objRS = Nothing
    End If
    objConn.Close
    Set objConn = Nothing


<%
 Response.End
End If
%>

LoBo
0
 
daveamourCommented:
Perhaps I should have also explained that I use the values rather than the constant names...

'---- CursorTypeEnum Values ----
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3

'---- LockTypeEnum Values ----
Const adLockReadOnly = 1
Const adLockPessimistic = 2
Const adLockOptimistic = 3
Const adLockBatchOptimistic = 4

Hope this helps!

Dave
0
 
daveamourCommented:
shastry I think teh error you would get in your suggestion would be that the Database is read only

Dave
0
 
yeggstryAuthor Commented:
daveamour, I have tried your suggestion, and the error that now comes up is:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] Cannot update. Database or object is read-only.

/HumanR/SPTR/useradd.asp, line 28
0
 
yeggstryAuthor Commented:
shstry, if I was to create an ODBC connection and establish DB connection via ODBC, how would I do it, and where would I put it in my code?
0
 
daveamourCommented:
Ok yeq, now the problem is that the IUSR_ServerName Account does not have write permissions on the database (as shastry_yedavalli) mentioned.

Do you have access to the administration of this server?

If so you need to assign Change permissions to IUSR_ServerName.  You can do this by right clicking on teh database then lciking properties and then permissions.  Find and Add the IUSR_ServerName and assign change permissions for the database.

Hope this helps

Dave
0
 
yeggstryAuthor Commented:
I don't have access to the admin for the server, so what can I do?
0
 
daveamourCommented:
You can ask whoever does have access I guess or you can host it somewhere else, perhaps www.brinkster.com who do free ASP hosting with database support.

Dave
0
 
yeggstryAuthor Commented:
Thanks for the suggestion davearmour, you deserve the points, especially as you have given me a free ASP hosting site that I did not know about!!!
0
 
sharad2Commented:
make "TblUsers" a sql query like this

tblusers="select * from table where 1=2"
it will give you blank recordset which you can add and update
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.