Click to See Complete Forum and Search --> : ASP error - Cannot update. Database or object is read-only.


impulse
10-20-2006, 11:17 AM
I am receiving this error when I submit my custadd.asp .

Error Type:
Microsoft JET Database Engine (0x80040E09)
Cannot update. Database or object is read-only.
/impcustomers/added.asp, line 30

added.asp line 30objRS.AddNew

I have checked the folder that contains the db and the db itself. They all have the write permission checked. Any suggestions?

russell
10-20-2006, 11:56 AM
what lock type are you opening the recordset with? needs to be adLockOptimistic or adLockPessimistic. see here (http://support.microsoft.com/kb/289675)

better to use INSERT statements to add data rather than rs.AddNew anyway

also, as in previous problem, any user opening the mdb will cause it to be read only for any other user, including your asp application

impulse
10-20-2006, 01:25 PM
I added adLockPessimistic to my code.

Error Message:
Microsoft JET Database Engine (0x80040E14)
Syntax error in INSERT INTO statement.
/impcustomers/added.asp, line 28

Line 28 is:
objRS.Open SQL, objConn, adLockPessimistic

<%@LANGUAGE="VBSCRIPT"%>
<% Option Explicit %>
<%

'get pass parameters
Dim strUserName
Dim strPassword
Dim intSLevel
Dim objConn
Dim SQL
Dim objRS
Dim adLockPessimistic

'get session variables
strUserName = Session("username")
strPassword = Session("userpass")
intSLevel = Session("sLevel")

'open connection to the database
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\db\IMPCustomers.mdb"

'set sql statement
SQL = "INSERT * INTO tblCustomerInfo WHERE 1=0"

'prepare recordset
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open SQL, objConn, adLockPessimistic

'collect customer info to add to the database
objRS("strCustFName") = Request.Form("cfname")
objRS("strCustLName") = Request.Form("clname")
objRS("strCustCompany") = Request.Form("ccomp")
objRS("strCustJobTitle") = Request.Form("cjob")
objRS("strCustAdd1") = Request.Form("cadd1")
objRS("strCustAdd2") = Request.Form("cadd2")
objRS("strCustCity") = Request.Form("ccity")
objRS("strCustState") = Request.Form("cstate")
objRS("strCustZipCode") = Request.Form("czip")
objRS("strCustCountry") = Request.Form("ccountry")
objRS("strCustBus") = Request.Form("cbus")
objRS("strCustFax") = Request.Form("cfax")
objRS("strCustMobile") = Request.Form("cmobile")
objRS("strCustEmail") = Request.Form("cemail")
objRS("strCustSalesRep") = Request.Form("csr")
objRS("strCustEmpContact") = Request.Form("cempcontact")
objRS.Update

%>

<!DOCTYPE html PUBLIC "-//W3C/DTD/ XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- This is the title of the page -->
<title>IMPulse NC Customer Database - Customer has been added.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!-- This starts the CSS for the page -->
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
font-size: relative;
font-weight: bold;
}
table {
background-color:#cccccc;
border-color:#CCCCCC;
}
</style>
<!-- CSS ends -->

<link href="dbcss.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="80%" border="1">
<tr>
<td>
<img src="art/dblogo.gif" width="322" height="74" />
</td>
</tr>
<tr>
<td>Thank you for adding <%=Response.Write(objRS("strCustFName"))%>&nbsp;<%=Response.Write(objRS("strCustLName"))%> to the database.</td>
</tr>
<tr>
<td><form action="custsearch.asp">
<input type="submit" name="Submit" value="Return to Search Page" />
</form></td>
</tr>
</table>
</body>
</html>
<%

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing

%>

russell
10-20-2006, 04:20 PM
that insert statement is wrong. insert syntax is like this

INSERT INTO myTable (fieldList) VALUES(valueList)

what exactly are u trying to do? b4 u had rs.AddNew, now rs.Update...?

If you are trying to just insert the form values, dont use recordset object. use conn.execute(sql) or even better use the command object

impulse
10-20-2006, 04:25 PM
I am trying to insert a new customer into the database.

impulse
10-20-2006, 04:27 PM
So my sql statement should be:

SQL = "INSERT INTO tblCustomerInfo (strCustFName, strCustLName, strCustCompany, strCustJobTitle, cjob, strCustAdd1, strCustAdd2, strCustCity, strCustState, strCustZipCode, strCustCountry, strCustBus, strCustFax, strCustMobile, strCustEmail, strCustSalesRep, strCustEmpContact VALUES('"& cfname &"','"& clname &"', '"& ccomp &"', '"& cjob &"', '"& cadd1 &"', '"& cadd2 &"', '"& ccity &"', '"& cstate &"', '"& czip &"', '"& ccountry &"', '"& cbus &"', '"& cfax &"', '"& cmobile &"', '"& cemail &"', '"& csr &"', '"& cempcontact &"')"

russell
10-20-2006, 08:58 PM
exactly.

then execute it like this

Dim cmd
Dim sql

Set cmd = Server.CreateObject("ADODB.Command")

sql = "......."

With cmd
.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\db\IMPCustomers.mdb"

.CommandType = 1
.CommandText = sql

.Execute 128 'adExecuteNoRecords
End With

Set cmd = Nothing

impulse
10-24-2006, 02:06 PM
I have made the changes. However, I have a new error message.

Error Type:
Microsoft JET Database Engine (0x80040E14)
Number of query values and destination fields are not the same.
/impcustomers/added.asp, line 52

What does this mean?

line 52: Set objRS = objCmd.Execute
<%@LANGUAGE="VBSCRIPT"%>
<% Option Explicit %>
<%

'get pass parameters
Dim strUserName
Dim strPassword
Dim intSLevel
Dim objConn
Dim SQL
Dim objCmd
Dim objRS
Dim adLockPessimistic
Dim cfname
Dim clname
Dim ccomp
Dim cjob
Dim cadd1
Dim cadd2
Dim ccity
Dim cstate
Dim czip
Dim ccountry
Dim cbus
Dim cfax
Dim cmobile
Dim cemail
Dim csr
Dim cempcontact

'get session variables
strUserName = Session("username")
strPassword = Session("userpass")
intSLevel = Session("sLevel")

'open connection to the database
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\db\IMPCustomers.mdb"

'set sql statement
SQL = "INSERT INTO tblCustomerInfo (strCustFName, strCustLName, strCustCompany, strCustJobTitle, cjob, strCustAdd1, strCustAdd2, strCustCity, strCustState, strCustZipCode, strCustCountry, strCustBus, strCustFax, strCustMobile, strCustEmail, strCustSalesRep, strCustEmpContact) VALUES('"& cfname &"','"& clname &"', '"& ccomp &"', '"& cjob &"', '"& cadd1 &"', '"& cadd2 &"', '"& ccity &"', '"& cstate &"', '"& czip &"', '"& ccountry &"', '"& cbus &"', '"& cfax &"', '"& cmobile &"', '"& cemail &"', '"& csr &"', '"& cempcontact &"')"

'create an instance of the command object
Set objCmd = Server.CreateObject("ADODB.Command")

'set the ActiveConnection and CommandText properties
objCmd.ActiveConnection = objConn
objCmd.CommandText = SQL

'prepare recordset object instance implicity using
'excute method of the Command object
Set objRS = objCmd.Execute

'collect customer info to add to the database
'objRS.AddNew
objRS("strCustFName") = Request.Form("cfname")
objRS("strCustLName") = Request.Form("clname")
objRS("strCustCompany") = Request.Form("ccomp")
objRS("strCustJobTitle") = Request.Form("cjob")
objRS("strCustAdd1") = Request.Form("cadd1")
objRS("strCustAdd2") = Request.Form("cadd2")
objRS("strCustCity") = Request.Form("ccity")
objRS("strCustState") = Request.Form("cstate")
objRS("strCustZipCode") = Request.Form("czip")
objRS("strCustCountry") = Request.Form("ccountry")
objRS("strCustBus") = Request.Form("cbus")
objRS("strCustFax") = Request.Form("cfax")
objRS("strCustMobile") = Request.Form("cmobile")
objRS("strCustEmail") = Request.Form("cemail")
objRS("strCustSalesRep") = Request.Form("csr")
objRS("strCustEmpContact") = Request.Form("cempcontact")
objRS.AddNew

%>

<!DOCTYPE html PUBLIC "-//W3C/DTD/ XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- This is the title of the page -->
<title>IMPulse NC Customer Database - Customer has been added.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!-- This starts the CSS for the page -->
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
font-size: relative;
font-weight: bold;
}
table {
background-color:#cccccc;
border-color:#CCCCCC;
}
</style>
<!-- CSS ends -->

<link href="dbcss.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="80%" border="1">
<tr>
<td>
<img src="art/dblogo.gif" width="322" height="74" />
</td>
</tr>
<tr>
<td>Thank you for adding <%=Response.Write(objRS("strCustFName"))%>&nbsp;<%=Response.Write(objRS("strCustLName"))%> to the database.</td>
</tr>
<tr>
<td><form action="custsearch.asp">
<input type="submit" name="Submit" value="Return to Search Page" />
</form></td>
</tr>
</table>
</body>
</html>
<%

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing

%>

russell
10-24-2006, 03:02 PM
u specify 17 fields to insert, but only 12 in your values list.

also, dont need a recordset to do an insert. can do it like my example above

impulse
10-24-2006, 03:44 PM
Don't I need a recordset for:

objRS("strCustFName") = Request.Form("cfname")
objRS("strCustLName") = Request.Form("clname")
objRS("strCustCompany") = Request.Form("ccomp")
objRS("strCustJobTitle") = Request.Form("cjob")
objRS("strCustAdd1") = Request.Form("cadd1")
objRS("strCustAdd2") = Request.Form("cadd2")
objRS("strCustCity") = Request.Form("ccity")
objRS("strCustState") = Request.Form("cstate")
objRS("strCustZipCode") = Request.Form("czip")
objRS("strCustCountry") = Request.Form("ccountry")
objRS("strCustBus") = Request.Form("cbus")
objRS("strCustFax") = Request.Form("cfax")
objRS("strCustMobile") = Request.Form("cmobile")
objRS("strCustEmail") = Request.Form("cemail")
objRS("strCustSalesRep") = Request.Form("csr")
objRS("strCustEmpContact") = Request.Form("cempcontact")
objRS.AddNew

russell
10-24-2006, 04:10 PM
not if u r executing an INSERT. tried the example i posted?

impulse
10-24-2006, 04:23 PM
Okay....I now have Error Type:
Microsoft JET Database Engine (0x80004005)
You cannot add or change a record because a related record is required in table 'tblSR'.
/impcustomers/added.asp, line 51

line 51.Execute 128 'adExecuteNoRecords

etylocus
10-25-2006, 03:51 AM
What kind of database are you using?
And who designed it?
It's probably access and probably, as stated in a previous post (http://www.webdeveloper.com/forum/archive/index.php/t-65011.html), the tables have check costraints. Remove those, and all should work.
Regarding your previous problem, if it's access somebody probably had the .mdb file open.

impulse
10-25-2006, 08:47 AM
I'm using access and I designed the database (my first access database). The tblCustomerInfo and tblSR are linked in Access. Sorry but I new to access. What do you mean "the tables have check costraints"?

etylocus
10-25-2006, 10:14 AM
I mean preciselly that "link" you talk about.
If those tables are linked, is there a record in tblSR for the record you're trying to add in tblCustomerInfo?
That's why you get a consistency error, probably.
You don't need to link the tables, unless you know what you're doing and/or what they're for, and check for these error you're getting.

impulse
10-25-2006, 02:17 PM
I removed the links between the two tables in access. I'm now getting the error message below:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
/impcustomers/added.asp, line 63
objRS("strCustFName") = Request.Form("cfname")

russell
10-25-2006, 03:13 PM
if you are executing an INSERT then do not use a recoirdset object.

did u ever try the sample i posted?

impulse
10-25-2006, 03:50 PM
Yes, however nothing is added to the database, just a id # but no data.

impulse
10-25-2006, 04:06 PM
Here is my customerr form to add to db:
<%@LANGUAGE="VBSCRIPT"%>
<% Option Explicit %>
<%
Dim strUserName
Dim strPassword
Dim intSLevel
'Dim objConn

'get pass parameters
strUserName = Session("username")
strPassword = Session("userpass")
intSLevel = Session("sLevel")
%>

<!DOCTYPE html PUBLIC "-//W3C/DTD/ XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- This is the title of the page -->
<title>IMPulse NC Customer Database - Add a customer!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!-- This starts the CSS for the page -->
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
font-size: relative;
font-weight: bold;
}
table {
background-color:#cccccc;
border-color:#CCCCCC;
}
</style>
<!-- CSS ends -->

<link href="dbcss.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="80%" border="1">
<tr>
<td>
<img src="art/dblogo.gif" width="322" height="74" />
</td>
</tr>

<table width="80%" border="1">
<form name="addCustomer" action="added.asp" method="post">
<tr>
<td>First Name:</td>
<td><input type="text" name="cfname" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="clname" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Company:</td>
<td><input type="text" name="ccomp" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Job Title</td>
<td><input type="text" name="cjob" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Address 1:</td>
<td><input type="text" name="cadd1" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Address 2:</td>
<td><input type="text" name="cadd2" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="ccity" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>State:</td>
<td><input type="text" name="cstate" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Zip Code:</td>
<td><input type="text" name="czip" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Country:</td>
<td><input type="text" name="ccountry" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Business Phone:</td>
<td><input type="text" name="cbus" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Fax:</td>
<td><input type="text" name="cfax" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Mobile:</td>
<td><input type="text" name="cmobile" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="cemail" size="25" maxlength="25" /></td>
</tr>
<tr>
<td>Sales Representative:</td>
<td>
<select name="csr">
<option value="Bob Poetsch">Bob Poetsch</option>
<option value="Chris Dennison">Chris Dennison</option>
<option value="Chris Pagni">Chris Pagni</option>
<option value="Hemant Khemka">Hemant Khemka</option>
<option value="Ignacio Kohler Dios">Ignacio Kohler Dios</option>
<option value="Mike Cottone">Mike Cottone</option>
<option value="Ricardo Capiello">Ricardo Capiello</option>
<option value="Scott Johnson">Scott Johnson</option>
<option value="Timothy Tang">Timothy Tang</option>
<option value="Zheng Li">Zheng Li</option>
<option value="IMPulse">IMPulse NC</option>
</select>
</td>
</tr>
<tr>
<td>IMPulse NC Contact:</td>
<td>
<select name="cempcontact">
<option value="Customer Service">Customer Service</option>
<option value="Engineering">Engineering</option>
<option value="Finance">Finance</option>
<option value="General Manager/President">General Manager/President</option>
<option value="Manufacturing">Manufacturing</option>
<option value="Purchasing">Purchasing</option>
<option value="Quality">Quality</option>
<option value="Sales/Marketing">Sales/Marketing</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="Added" value="Select to add customer to database!" />
</td>
</tr>
</form>
</table>

</table>
</body>
</html>

<!-- JavaScript starts here -->
<!-- Places text blinker in the cfname text box -->
<script language="javascript" type="text/javascript">
{
document.addCustomer.cfname.focus();
}
</script>
<!-- javascript ends here -->

Here is the added.asp that insert my new customer:
<%@LANGUAGE="VBSCRIPT"%>
<% Option Explicit %>
<%

'get pass parameters
Dim strUserName
Dim strPassword
Dim intSLevel
Dim objConn
Dim SQL
Dim objCmd
Dim objRS
Dim adLockPessimistic
Dim cfname
Dim clname
Dim ccomp
Dim cjob
Dim cadd1
Dim cadd2
Dim ccity
Dim cstate
Dim czip
Dim ccountry
Dim cbus
Dim cfax
Dim cmobile
Dim cemail
Dim csr
Dim cempcontact

'get session variables
strUserName = Session("username")
strPassword = Session("userpass")
intSLevel = Session("sLevel")

'open connection to the database
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\db\IMPCustomers.mdb"

Set objCmd = Server.CreateObject("ADODB.Command")

'set sql statement
SQL = "INSERT INTO tblCustomerInfo (strCustFName, strCustLName, strCustCompany, strCustJobTitle, strCustAdd1, strCustAdd2, strCustCity, strCustState, strCustZipCode, strCustCountry, strCustBus, strCustFax, strCustMobile, strCustEmail, strCustSalesRep, strCustEmpContact) VALUES('"& cfname &"','"& clname &"', '"& ccomp &"', '"& cjob &"', '"& cadd1 &"', '"& cadd2 &"', '"& ccity &"', '"& cstate &"', '"& czip &"', '"& ccountry &"', '"& cbus &"', '"& cfax &"', '"& cmobile &"', '"& cemail &"', '"& csr &"', '"& cempcontact &"')"

With objCmd
.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\db\IMPCustomers.mdb"

.CommandType = 1
.CommandText = sql

.Execute 128 'adExecuteNoRecords

End With

Set objCmd = Nothing

'prepare recordset object instance implicity using
'excute method of the Command object
'Set objRS = objCmd.Execute

'collect customer info to add to the database
'objRS.AddNew
'objRS("strCustFName") = Request.Form("cfname")
'objRS("strCustLName") = Request.Form("clname")
'objRS("strCustCompany") = Request.Form("ccomp")
'objRS("strCustJobTitle") = Request.Form("cjob")
'objRS("strCustAdd1") = Request.Form("cadd1")
'objRS("strCustAdd2") = Request.Form("cadd2")
'objRS("strCustCity") = Request.Form("ccity")
'objRS("strCustState") = Request.Form("cstate")
'objRS("strCustZipCode") = Request.Form("czip")
'objRS("strCustCountry") = Request.Form("ccountry")
'objRS("strCustBus") = Request.Form("cbus")
'objRS("strCustFax") = Request.Form("cfax")
'objRS("strCustMobile") = Request.Form("cmobile")
'objRS("strCustEmail") = Request.Form("cemail")
'objRS("strCustSalesRep") = Request.Form("csr")
'objRS("strCustEmpContact") = Request.Form("cempcontact")
'objRS.AddNew

%>

<!DOCTYPE html PUBLIC "-//W3C/DTD/ XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- This is the title of the page -->
<title>IMPulse NC Customer Database - Customer has been added.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!-- This starts the CSS for the page -->
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
font-size: relative;
font-weight: bold;
}

table {
background-color:#cccccc;
border-color:#CCCCCC;
}
</style>
<!-- CSS ends -->

<link href="dbcss.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="80%" border="1">
<tr>
<td>
<img src="art/dblogo.gif" width="322" height="74" />
</td>
</tr>
<tr>
<td>Thank you for adding to the database.</td>
</tr>
<tr>
<td><form action="custsearch.asp">
<input type="submit" name="Submit" value="Return to Search Page" />
</form></td>
</tr>
</table>
</body>
</html>
<%

'objRS.Close
'Set objRS = Nothing
objConn.Close
Set objConn = Nothing

%>

russell
10-25-2006, 10:27 PM
you got it...just forgot to assign your form values to your variables:


Dim cfname
Dim clname
Dim ccomp
Dim cjob
Dim cadd1
Dim cadd2
Dim ccity
Dim cstate
Dim czip
Dim ccountry
Dim cbus
Dim cfax
Dim cmobile
Dim cemail
Dim csr
Dim cempcontact

cfname = Request.Form("cfname")
clname = Request.Form("clname")
ccomp = Request.Form("ccomp")
cjob = Request.Form("cjob")
cadd1 = Request.Form("cadd1")
cadd2 = Request.Form("cadd2")
ccity = Request.Form("ccity")
cstate = Request.Form("cstate")
czip = Request.Form("czip")
ccountry = Request.Form("ccountry")
cbus = Request.Form("cbus")
cfax = Request.Form("cfax")
cmobile = Request.Form("cmobile")
cemail = Request.Form("cemail")
csr = Request.Form("csr")
cempcontact = Request.Form("cempcontact")

impulse
10-26-2006, 08:33 AM
Thanks for all of your help!