1
我在這裏使用.dbf文件有問題。我可以進行CRUD操作,但是當我嘗試使用事務時,我收到異常。 我做這樣的:如何使用Odbc在.DBF文件上使用事務?
public void AddRolesToUser(string user, string[] roles)
{
using (OdbcConnection connection = new OdbcConnection(ConnectionString))
{
OdbcCommand command = new OdbcCommand();
OdbcTransaction transaction = null;
command.Connection = connection;
try
{
connection.Open();
transaction = connection.BeginTransaction();
command.Connection = connection;
command.Transaction = transaction;
command.CommandText = "Delete From Roles Where User='" + user + "'";
command.ExecuteNonQuery();
if (roles != null)
{
foreach (string role in roles)
{
command.CommandText = "Insert Into Roles(User, Role) Values('" + user + "', '" + role + "')";
command.ExecuteNonQuery();
}
}
transaction.Commit();
}
catch(OdbcException ex)
{
transaction.Rollback();
}
}
}
當它擊中connection.BeginTransaction()我得到這個例外
[Microsoft][ODBC dBase Driver]Optional feature not implemented
這是我的ConnectionString
"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;" + "Dbq=" + root + ";"
我再說一遍,我可以讓CRUD操作正常。
看起來像你運氣不好,DBF或ODBC驅動程序不支持事務。 – Bobby 2010-09-06 13:13:08