www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: ASP error - Cannot update. Database or object is read-only.

  1. #1
    Join Date
    Dec 2002
    Posts
    146

    ASP error - Cannot update. Database or object is read-only.

    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 30
    HTML Code:
    objRS.AddNew
    I have checked the folder that contains the db and the db itself. They all have the write permission checked. Any suggestions?

  2. #2
    Join Date
    Feb 2003
    Posts
    2,745
    what lock type are you opening the recordset with? needs to be adLockOptimistic or adLockPessimistic. see here

    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

  3. #3
    Join Date
    Dec 2002
    Posts
    146

    syntax error

    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

    HTML Code:
    <%@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
    
    %>

  4. #4
    Join Date
    Feb 2003
    Posts
    2,745
    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

  5. #5
    Join Date
    Dec 2002
    Posts
    146
    I am trying to insert a new customer into the database.

  6. #6
    Join Date
    Dec 2002
    Posts
    146
    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 &"')"

  7. #7
    Join Date
    Feb 2003
    Posts
    2,745
    exactly.

    then execute it like this
    Code:
    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

  8. #8
    Join Date
    Dec 2002
    Posts
    146
    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
    Code:
    <%@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
    
    %>

  9. #9
    Join Date
    Feb 2003
    Posts
    2,745
    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

  10. #10
    Join Date
    Dec 2002
    Posts
    146
    Don't I need a recordset for:

    Code:
    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

  11. #11
    Join Date
    Feb 2003
    Posts
    2,745
    not if u r executing an INSERT. tried the example i posted?

  12. #12
    Join Date
    Dec 2002
    Posts
    146
    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
    Code:
    .Execute 128 'adExecuteNoRecords

  13. #13
    Join Date
    Oct 2006
    Posts
    59
    What kind of database are you using?
    And who designed it?
    It's probably access and probably, as stated in a previous post, 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.

  14. #14
    Join Date
    Dec 2002
    Posts
    146
    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"?

  15. #15
    Join Date
    Oct 2006
    Posts
    59
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12240 seconds
  • Memory Usage 3,019KB
  • Queries Executed 13 (?)
More Information
Template Usage (37):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (2)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates