Solved

Database Problem

Posted on 2001-09-05
14
183 Views
Last Modified: 2008-03-10
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

0
Comment
Question by:yeggstry
14 Comments
 
LVL 19

Expert Comment

by:daveamour
ID: 6456693
Try changing this line

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

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

Dave
         
0
 

Expert Comment

by:shastry_yedavalli
ID: 6456696
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
 
LVL 19

Expert Comment

by:daveamour
ID: 6456702
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
 

Expert Comment

by:LOBO
ID: 6456703
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
 
LVL 19

Expert Comment

by:daveamour
ID: 6456708
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
 
LVL 19

Expert Comment

by:daveamour
ID: 6456710
shastry I think teh error you would get in your suggestion would be that the Database is read only

Dave
0
 

Author Comment

by:yeggstry
ID: 6456795
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:yeggstry
ID: 6456804
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
 
LVL 19

Expert Comment

by:daveamour
ID: 6456844
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
 

Author Comment

by:yeggstry
ID: 6456916
I don't have access to the admin for the server, so what can I do?
0
 
LVL 19

Expert Comment

by:daveamour
ID: 6456937
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
 

Author Comment

by:yeggstry
ID: 6456997
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
 
LVL 19

Accepted Solution

by:
daveamour earned 100 total points
ID: 6457051
Thanks
0
 

Expert Comment

by:sharad2
ID: 6463156
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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now