oledb exception: the database engine could not lock table

1.6k Views Asked by At

I have a C# application that interacts with an Access database.
When I execute an OleDbCommand object to ALTER a table and ADD a new column, I receive an error:

OleDbException: The database engine could not lock table because it is already in use by another person or process.

While I can manipulate my data successfully. However when I execute the query directly in the MS Access, it works correctly.

Note: my database is closed and no person or process is using it.

How can I resolve this?

1

There are 1 best solutions below

4
On

Try this out

Use following connection string

db.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\<Your database name>;Persist Security Info=False;")

along with following additional property

db.Properties("Jet OLEDB:Connection Control") = 1

In short, you need to open the database in exclusive mode to make an alter table query. or you can also set this property in the following manner in c#

CN.Mode =adModeShareExclusive

I have not tested the code though but it should work for you.