I am using MS Access Database with C# and creating a web service. For connection with database I am using following code
String databasePath = @"C:\inetpub\wwwroot\02 CustomerCreate\CustomerCreate\adResDemo.mdb";
String Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + databasePath + ";Persist Security Info=False";
//Connection to database
con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + databasePath + ";Persist Security Info=False");
con.Open();
Now I am inserting some rows in a table using code. I am using following code for that
//Query For ZipCode Insertion
String zipQuery = "INSERT INTO ZipCodes(ZipCode, City, State, DeliveryCharge, DeliveryComp, AutoID, RowGUID) VALUES ('" + PostCode + "','" + City + "','" + State + "'," + DeliveryCharge + "," + DeliveryComp + "," + AutoID + ",'" + RowGUIDZipCode + "')";
//Inserts query ZipCodes Table
cmd = new OleDbCommand(zipQuery, con);
cmd.ExecuteNonQuery();
Now when I am running above code directly on Visual Studio then its working fine and entries in database taking place. But when I am deploying this web service on IIS server cmd.ExecuteNonQuery() throwing a run time exception and its not inserting any values in database.
Exception
System.Data.OleDb.OleDbException: Operation must use an updateable query.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult 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 CustomerCreate.Service1.createCustomer(String FirstName, String LastName, String EmailAddress, String CompanyName, String StreetAddress, String PostCode, String City, String State, String Country, String PhoneNumber) in C:\inetpub\wwwroot\02 CustomerCreate\CustomerCreate\Service1.asmx.cs:line 141
What type of issue is that?
Am not sure but it seems you need a modify permission on the folder containing the mdb file you are trying to connect to.
To set this permission:
Right click on the App_Data folder (or whichever other folder you have put the mdb file in) and select Properties. Look for the Security tab. If you can’t see it, you need to go to My Computer, then click Tools and choose Folder Options…. then click the View tab. Scroll to the bottom and uncheck “Use simple file sharing (recommended)”. Back to the Security tab, you need to add the relevant account to the Group or User Names box. Click Add…. then click Advanced, then Find Now. The appropriate account should be listed. Double click it to add it to the Group or User Names box, then check the Modify option in the permissions. That’s it. You are done.
Taken from this link