我一直在研究一个连接到访问数据库的c#项目,但是某个事件序列会导致它崩溃AccessViolationException
问题是在使用oledb以与savefiledialog不同的单独形式调用数据库连接之后,而不是调用savefiledialog1.ShowDialog()
注意:这也适用于打开文件对话框。
答案 0 :(得分:1)
答案 1 :(得分:0)
确保使用System.data.dll中的System.Data.OleDb
然后尝试这样的事情:
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
// Declare Command
OleDbCommand command = new OleDbCommand(YourSQL);
// Set the Connection to the new OleDbConnection.
command.Connection = connection;
// Open the connection and execute the command.
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
答案 2 :(得分:0)
我也有类似的问题,这对我有所帮助: 我添加了" OLE DB服务= -1"在我的connectionstring中,现在问题已经解决了。
请参阅:http://www.codeproject.com/Questions/106826/OpenFileDialog-plus-OleDbConnection-equals-AccessV.aspx解决方案8