3

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?

3
  • Has IUSR got permissions on the folder and the mdb file? Commented Oct 4, 2012 at 12:59
  • @Remou I don't know how to get permissions for IUSR. But I have enable Anonymous Authentication. Commented Oct 4, 2012 at 13:07
  • Please tell me that zip code data isn't coming direct from user input and that there are no locale specific columns such as date or decimal. Commented Oct 4, 2012 at 13:18

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much its yeah the folder was not permitted for writing operation. Now its working on IIS server too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.