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

Database recordset are read

Status
Not open for further replies.

mmarkym

Programmer
Mar 23, 2002
54
US
I've set up my database and have a table. I'm trying to use the ADO Connection object and recordset object to connect to the database and insert a query from a HTML form. The database is on a remote server at Lunarpages.com. I'm getting the error message below. I've tried reconfiguring the database but still won't work.


Error Type:
ADODB.Recordset.1 (0x80004005)
Recordset is read-only

the code reads in part as follows--

strFname = request.form("fname")
strLname = request.form("lname")
strStreet = request.form("street")
strCity = request.form("city")
strState = request.form("state")
intZip = request.form("zip")
intPhone = request.form("phone")
intNum = request.form("number")
intTime = request.form("time")
intDate = request.form("date")
strEmail = request.form("email")

set objConn = server.createobject("ADODB.connection")

set objRS = server.createobject("ADODB.recordset")

strConnectionString = "Driver={mySQL}; Server=localhost; Port=3306; Option=0; Socket=; Stmt=; Database=dbname; Uid=user; Pwd=pass;"

objConn.open strConnectionString

objRS.Open "Reservations", objConn

objRS.AddNew

objRS("fname") = strFname
objRS("lname") = strLname
objRS("street") = strStreet
objRS("city") = strCity
objRS("state") = strState
objRS("zip") = intZip
objRS("phone") = intPhone
objRS("number") = intNum
objRS("time") = intTime
objRS("date") = intDate
objRS("email") = strEmail

objRS.update

objRS.close

objConn.close
 
Hi...
OK, when you open a recordset, you have to specify the cursortype and locktype, if not, the cursortype will be : adOpenforwardOnly and the locktype will be adLockReadOnly.
that's why you get the readonly error...
so try somrthing like this :
Code:
objRS.Open "Reservations", objConn, 3, 3

which the first 3 is for cursortype which is : adOpenStatic
and the second 3 is for locktype which is : adLockOptimistic

you can use MSDN to find out about other cursortype and locktypes.

----
Harsh words break no bones but they do break hearts.
E.T.
 
OK now I'm getting this error and have no idea what it means. I'll paste the whole code.

Error Type:
ADODB.Recordset.1 (0x80004005)
SQLState: S1000 Native Error Code: 1062 [TCX][MyODBC]Duplicate entry '97' for key 1


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<meta name="Microsoft Border" content="t, default">
</head>

<body><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>

<p>&nbsp;</p>

</td></tr><!--msnavigation--></table><!--msnavigation--><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><!--msnavigation--><td valign="top">

<%

dim strFname
dim strLname
dim strStreet
dim strCity
dim strState
dim intZip
dim intPhone
dim intNum
dim intTime
dim intDate
dim strEmail
dim strConnectionString
dim objRS
dim objConn
dim strQ

strFname = request.form("fname")
strLname = request.form("lname")
strStreet = request.form("street")
strCity = request.form("city")
strState = request.form("state")
intZip = request.form("zip")
intPhone = request.form("phone")
intNum = request.form("number")
intTime = request.form("time")
intDate = request.form("date")
strEmail = request.form("email")

set objConn = server.createobject("ADODB.connection")

set objRS = server.createobject("ADODB.recordset")

strConnectionString = "Driver={mySQL}; Server=localhost; Port=3306; Option=0; Socket=; Stmt=; Database=markli4_; Uid=markli4; Pwd=daisey;"

'strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; dATAsOURCE= C:\Documents and Settings\Administrator\My Documents\My Webs\myAccessDatabase; Persist security info=false"

objConn.open strConnectionString

objRS.Open "Reservations", objConn, 3, 3

objRS.AddNew

objRS("fname") = strFname
objRS("lname") = strLname
objRS("street") = strStreet
objRS("city") = strCity
objRS("state") = strState
objRS("zip") = intZip
objRS("phone") = intPhone
objRS("number") = intNum
objRS("time") = intTime
objRS("date") = intDate
objRS("email") = strEmail

objRS.update


response.write "<table border='1' bordercolor='#800000' width='30%' bgcolor='cccccc' colspan='2' align='center'>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "First Name: " & "</TD></B>"

response.write "<TD align='center'>" & strFname & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "Last Name: " & "</TD></B>"

response.write "<TD align='center'>" & strLname & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "Street: " & "</TD></B>"

response.write "<TD align='center'>" & strStreet & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "City: " & "</TD></B>"

response.write "<TD align='center'>" & strCity & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "State: " & "</TD></B>"

response.write "<TD align='center'>" & strState & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "Zip Code: " & "</TD></B>"

response.write "<TD align='center'>" & intZip & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "Phone #: " & "</TD></B>"

response.write "<TD align='center'>" & intPhone & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "Number: " & "</TD></B>"

response.write "<TD align='center'>" & intNum & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "Time: " & "</TD></B>"

response.write "<TD align='center'>" & intTime & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "Date: " & "</TD></B>"

response.write "<TD align='center'>" & intDate & "</td></TR>"

response.write "<TR><TD align='center'>"

response.write "<B>" & "E-Mail: " & "</TD></B>"

response.write "<TD align='center'>" & strEmail & "</td></TR></table>"



objRS.close

objConn.close


%>

</body>
</html>
 
Hi...
do you have any primary key in yourtable ?
I think the error is because of you are inserting a duplicate value in your primary key...
check your fields in your DB...

----
Harsh words break no bones but they do break hearts.
E.T.
 
OK, thanx for that fix, but now I'm getting this error which I don't understand.

Error Type:
ADODB.Recordset.1 (0x800A0E79)
Invalid operation on open object

this added code from above

strQ = "Select * from Reservations"

objRS.open strQ, objConn, adOpenForwardOnly
if bug then response.write "<br>debug: Objrs.Open: " & err.number


if objRS.eof then

response.write "no records found"

else

while not objRS.eof

strQ = " "
strQ = strQ & "<table border='1' bordercolor='#800000' width='30%' bgcolor='cccccc' colspan='2' align='center'>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "First Name: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & strFname & "</td></TR>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "Last Name: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & strLname & "</td></TR>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "Street: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & strStreet & "</td></TR>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "City: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & strCity & "</td></TR>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "State: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & strState & "</td></TR>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "Zip Code: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & intZip & "</td></TR>"

'response.write "<TR><TD align='center'>"

'response.write "<B>" & "Phone #: " & "</TD></B>"

'response.write "<TD align='center'>" & intPhone & "</td></TR>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "Number: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & intNum & "</td></TR>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "Time: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & intTime & "</td></TR>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "Date: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & intDate & "</td></TR>"

strQ = strQ & "<TR><TD align='center'>"

strQ = strQ & "<B>" & "E-Mail: " & "</TD></B>"

strQ = strQ & "<TD align='center'>" & strEmail & "</td></TR></table>"

response.write strQ

objRS.MoveNext

wend

end if
 
Hi...
I don't see any error in this code, except the Bug which I think it's a function of your own...
so, if it's possible, please post your complete code, maybe it be more useful...

----
Harsh words break no bones but they do break hearts.
E.T.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top