0

I have created a .Net 4.5 application that reads and writes to MS Access database. While running the application on my machine (which has MS office) everything is fine but when I run this on my server (which does not has MS Office but has ACE ) I get the object reference not set to an instance of an object.

This happens when I click the button. Following is the code

 try
        {
            OleDbConnection conn = new OleDbConnection(connectionString);
            conn.Open();
            est_index = getTableIndex(conn,estimateTableIndex);

            for (int i = 0; i < inputValues.Count; i++)
            {
                string FieldName = "";
                string FieldValue = "";
                if (inputValues[i] is System.Web.UI.WebControls.TextBox)
                {
                    FieldName = inputValues[i].ClientID;
                    FieldValue = ((System.Web.UI.WebControls.TextBox)(inputValues[i])).Text;
                }
                else
                {
                    FieldName = inputValues[i].ClientID;
                    FieldValue = ((System.Web.UI.WebControls.DropDownList)(inputValues[i])).SelectedValue;
                }
                //everything fine till here..then throws the error below
                string my_querry = "INSERT INTO Estimate VALUES(@Est_id,@FieldName,@FieldValue)";
                OleDbCommand cmd = new OleDbCommand(my_querry, conn);
                cmd.Parameters.AddWithValue("@Est_id", est_index);
                cmd.Parameters.AddWithValue("@FieldName", FieldName);
                cmd.Parameters.AddWithValue("@FieldValue", FieldValue);
                cmd.ExecuteNonQuery();

            }
            conn.Close();
        }
        catch (Exception e)
        {
            Console.Write(e.InnerException.Message);
        }

Not sure why this is happening ?

EDIT: I created a virtual machine and downloaded the ACE and the same error occurred that clients face

EDIT 2: The connection string looks like "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\cohber.accdb" I tried to debug and see where the code broke and it broke at cmd.ExecuteNonQuery();. The message at exception was operation must use an updateable query

Edit 3: the MS Access file is located in c driver. I gave all the users full permission but still get the error

user3342812
  • 343
  • 8
  • 25
  • 1
    It usually helps when you tell us which line throws the exception. – LarsTech Mar 15 '16 at 19:10
  • Verify if you have this http://stackoverflow.com/questions/13451085/exception-when-addwithvalue-parameter-is-null – Steve Mar 15 '16 at 19:20
  • Please include the connection string: you may rename db and folders to protect sensitive data, but we have to look a its structure. Also, what Access Db version are you using? Thanks and regards, – Alexander Bell Mar 15 '16 at 21:34
  • The connection string looks like "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\Users\karan\Documents\cohber.accdb" I tried to debug and see where the code broke and it broke at cmd.ExecuteNonQuery();. The message at exception was operation must use an updateable query – user3342812 Mar 15 '16 at 22:36

1 Answers1

0

You need to set read/ write permissions to the folder containing the access .mdb file

Dan
  • 1