Problem while inserting record in Access DB using ASP.NET
-
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 :)
-
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 :)
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
-
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
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