如何使用 Odbc 在 .DBF 文件上使用事务?
我在这里使用 .dbf 文件时遇到问题。我可以进行 CRUD 操作,但当我尝试使用事务时出现异常。 我这样做:
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
这是我的连接字符串
"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;" + "Dbq=" + root + ";"
我重复,我可以使CRUD操作正常。
I have a problem here using .dbf files. I can make CRUD operations but i get an exception when i try to use transactions.
I am doing like this:
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();
}
}
}
When it hits connection.BeginTransaction() i get this exception
[Microsoft][ODBC dBase Driver]Optional feature not implemented
This is my connectionstring
"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;" + "Dbq=" + root + ";"
I repeat , i can make CRUD operations ok.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DBF 文件是一个简单的数据存储 - 它们只是带有关联索引文件的随机访问文件。没有进程或控制文件来控制允许事务所需的锁定和回滚。
如果您需要交易,则必须更改文件存储。
DBF files are a simple datastore - they are just random access files with associated index files. There is no process or control file to control locking and rollbacks which would be needed to allow transactions.
If you need transactions you will have to change your file store.