"pyodbc.Error: Record Locked by Another User in Microsoft Access Database"

32 views Asked by At

"When attempting to execute a database operation using pyodbc in Python, specifically an INSERT or UPDATE operation on a Microsoft Access database, an error occurs indicating that the operation could not be completed because the record is currently locked by another user.

The error message is:

pyodbc.Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver] Could not update; currently locked by user 'admin' on machine 'SAEED'. (-1102) (SQLExecDirectW)")."

I tried to:

Attempted to execute SQL statements (such as INSERT or UPDATE) using pyodbc in your Python script to modify records in a Microsoft Access database.

I expected:

I expected the SQL statements to execute successfully and update/insert records in the Access database without any errors.

I expected to be able to modify the records in the database without encountering any locking issues.

I might have expected to handle concurrent access to the database more gracefully, such as by waiting for locks to be released or by implementing a mechanism to avoid conflicts.

Here's part of my code:

cursor.execute(create_table_query)
        conn.commit()

        # Insert data into the table
        insert_query = f'''
        INSERT INTO {table_name} (Province, County, District, City, Region, Neighborhood, Title, Address, Type, FClass, Latitude, Longitude)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
        '''
        cursor.execute(insert_query, (
            data['province'],
            data['county'],
            data['district'],
            data['city'],
            data['region'],
            data['neighborhood'],
            data['title'],
            data['address'],
            data['type'],
            data['fclass'],
            data['geom']['coordinates'][1],  # Latitude
            data['geom']['coordinates'][0]   # Longitude
        ))
        conn.commit()
0

There are 0 answers