Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem while inserting record in Access DB using ASP.NET

Problem while inserting record in Access DB using ASP.NET

Scheduled Pinned Locked Moved ASP.NET
databasehelpcsharpasp-netcom
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Its Adnan
    wrote on last edited by
    #1

    I have written follwing code for inserting a record: ----------------------------------------------------- Dim MyConnection As OleDbConnection Dim MyCommand As OleDbCommand Dim InsertCmd As String = "INSERT INTO tblEmployees(EmailName, FirstName, HomePhone, LastName, MiddleName) " & _ "VALUES ('test@test.com', 'Test', 'Test', '123456', '-')" MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=C:\Inetpub\wwwroot\TestHTTPDBSyncWeb" & _ "Srv\DB\dbTest.mdb") MyCommand = New OleDbCommand(InsertCmd, MyConnection) MyCommand.Connection.Open() Try MyCommand.ExecuteNonQuery() strStatus = "Record Added:" & InsertCmd.ToString() Catch Exp As Exception strStatus = "ERROR: " & Exp.Message & vbCr & Exp.StackTrace End Try MyCommand.Connection.Close() -------------------------------------------------- and resulkts in following exception --------------------------------------------------- ERROR: Operation must use an updateable query. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at TestHTTPDBSyncWebSrv.SyncDBSrv.addJunkRecordDirect() in c:\inetpub\wwwroot\TestHTTPDBSyncWebSrv\SyncDBSrv.asmx.vb:line 249 -------------------------------------------------------------- The same code run fine if executed from VB application, and fails if used in ASP.NET or ASP.NET webservice. What might be the problem :)

    T 1 Reply Last reply
    0
    • I Its Adnan

      I have written follwing code for inserting a record: ----------------------------------------------------- Dim MyConnection As OleDbConnection Dim MyCommand As OleDbCommand Dim InsertCmd As String = "INSERT INTO tblEmployees(EmailName, FirstName, HomePhone, LastName, MiddleName) " & _ "VALUES ('test@test.com', 'Test', 'Test', '123456', '-')" MyConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=C:\Inetpub\wwwroot\TestHTTPDBSyncWeb" & _ "Srv\DB\dbTest.mdb") MyCommand = New OleDbCommand(InsertCmd, MyConnection) MyCommand.Connection.Open() Try MyCommand.ExecuteNonQuery() strStatus = "Record Added:" & InsertCmd.ToString() Catch Exp As Exception strStatus = "ERROR: " & Exp.Message & vbCr & Exp.StackTrace End Try MyCommand.Connection.Close() -------------------------------------------------- and resulkts in following exception --------------------------------------------------- ERROR: Operation must use an updateable query. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at TestHTTPDBSyncWebSrv.SyncDBSrv.addJunkRecordDirect() in c:\inetpub\wwwroot\TestHTTPDBSyncWebSrv\SyncDBSrv.asmx.vb:line 249 -------------------------------------------------------------- The same code run fine if executed from VB application, and fails if used in ASP.NET or ASP.NET webservice. What might be the problem :)

      T Offline
      T Offline
      Thea Burger
      wrote on last edited by
      #2

      Hi, Usually you get this message because the your ASPNET account doesn't have sufficient permissions to access the database. Try this: -Configure the ASP.NET worker process to run under the SYSTEM account in the section of the Machine.config file. -For security reasons, Microsoft recommends that you enable impersonation on your ASP.NET application. This method works if the impersonated user has necessary permissions to the computer and the database that you are accessing. If you need more info, go to http://support.microsoft.com/default.aspx?scid=kb;en-us;316675. A more lenghty explanation is given there. HTH, Thea

      M 1 Reply Last reply
      0
      • T Thea Burger

        Hi, Usually you get this message because the your ASPNET account doesn't have sufficient permissions to access the database. Try this: -Configure the ASP.NET worker process to run under the SYSTEM account in the section of the Machine.config file. -For security reasons, Microsoft recommends that you enable impersonation on your ASP.NET application. This method works if the impersonated user has necessary permissions to the computer and the database that you are accessing. If you need more info, go to http://support.microsoft.com/default.aspx?scid=kb;en-us;316675. A more lenghty explanation is given there. HTH, Thea

        M Offline
        M Offline
        mikhaelb
        wrote on last edited by
        #3

        I am seeing the same problem when running on a Windows 2003 server. My code works just fine on my local PC and a windows 2000 server. The system admin claims that all permissions are set properly. Both servers are with the same hosting company. Thanks, Mike

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups