我创建了一个读写MS Access数据库的.Net 4.5应用程序。在我的机器上运行应用程序(有MS办公室)一切都很好但是当我在我的服务器上运行它(没有MS Office但有ACE)时,我得到了object reference not set to an instance of an object
。
单击按钮时会发生这种情况。以下是代码
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);
}
不确定为什么会这样?
编辑:我创建了一个虚拟机并下载了ACE,并且发生了客户端面临的相同错误
编辑2:连接字符串看起来像"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\cohber.accdb"
我尝试调试并查看代码在哪里破坏,并在cmd.ExecuteNonQuery();
处破坏。异常消息为operation must use an updateable query
编辑3:MS Access文件位于c驱动程序中。我给了所有用户完全权限,但仍然收到错误
答案 0 :(得分:0)
您需要为包含访问.mdb文件的文件夹设置读/写权限