如何使用 Odbc 在 .DBF 文件上使用事务?

发布于 2024-09-18 01:18:17 字数 1541 浏览 11 评论 0原文

我在这里使用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠我空喜 2024-09-25 01:18:17

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文