tags:

views:

25

answers:

1

Hi 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.

+3  A: 

DNF 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.

Mark