Joseph
Joseph

Reputation: 661

Submit button works normally locally, but on the web server, it gives me an error

So when I click my button on my webpage, it works fine if I do it locally. If I do it on my GoDaddy webserver, it gives me a "operation must be updateable query" error, and points to the com.ExecuteNonQuery in my code. Here is the C# for the error:

 protected void submitForMail(object sender, EventArgs e)
{
    string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\TravelJoansDB.mdb;";
    string cmdstr = "INSERT INTO EmailList(FirstName,LastName,EmailAddress) VALUES (@FirstName, @LastName, @EmailAddress)";
    OleDbConnection con = new OleDbConnection(constr);
    OleDbCommand com = new OleDbCommand(cmdstr, con);
    TextBox tFirstName = (TextBox)FormView1.FindControl("FirstName");
    TextBox tLastName = (TextBox)FormView1.FindControl("LastName");
    TextBox tEmail = (TextBox)FormView1.FindControl("EmailAddress");
    con.Open();
    com.Parameters.AddWithValue("@FirstName", tFirstName.Text);
    com.Parameters.AddWithValue("@LastName", tLastName.Text);
    com.Parameters.AddWithValue("@EmailAddress", tEmail.Text);
    com.ExecuteNonQuery();
    con.Close();
    string EmailAdded = "Your E-mail address has been added.";
    System.Console.Write(EmailAdded);
}

I don't want to update any record in the table, I want to insert them into the table. So why is it telling me that the operation needs to be an updateable query?

Upvotes: 1

Views: 240

Answers (2)

Joseph
Joseph

Reputation: 661

It was indeed a permissions error, but I didn't know that I could set permissions on GoDaddy's servers. I found a link for it here. This solved my problems. Thanks everyone!

Upvotes: 0

C Sharper
C Sharper

Reputation: 8626

User running this program does not have permissions to access the database file.

Check and modify the permissions as per your conditions.

You can also consider changing the location of the database file to another, more asily accessible folder.

Also check if file is located in program files folder, If it is so, then it creates permission issues for user.

Permission Setting Method:

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.

Upvotes: 1

Related Questions