通过 OleDb (C#) 将 Access 2010 记录锁定设置为乐观锁定
Set Access 2010 record locking to optimistic locking through OleDb (C#)
我正在通过 C# 中的 OleDb 与 Access 2010 通信。
如何设置 锁定类型 以使用来自 C# 的 乐观锁定 ?
如果有人想知道,我正在使用此连接字符串连接到我的 Access 数据库:
// Set the data source string.
_sqlCon = new OleDbConnection(
String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True", databasePath)
);
更新 #0
我从 Microsoft MSDN 网站 (https://msdn.microsoft.com/en-us/library/ee252458(v=bts.10).aspx) 的 ADO 中找到了一些关于 adLockOptimistic
的信息,这些信息可能完全不相关,因为我使用的是 OLE.
更新 #1
我尝试将以下内容添加到连接字符串中:
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;LockType=3;"
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;Lock Type=3;"
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;LockType=adLockOptimistic;"
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;Lock Type=adLockOptimistic;"
所有这些都会导致以下异常:
Could not find installable ISAM.
我预计它不会起作用,但是,嘿,谁知道你是否不尝试。
更新 #2
如果可以在我的 Access 数据库中定义此 属性,该解决方案也非常好!但是,这应该是数据库设置而不是客户端特定设置,并且 如果 可以从 C# 中实现,该方法符合我的偏好。
上下文信息:
I am doing a concurrency stress-test on my Access database (over a network). I have about 20+
clients (little C# programs) that are reading the same record from
the same table as fast as possible for each client. This gives a lot of database is in 'Admin' mode by ..
exceptions and I catch these exceptions in my little C# client. I want to
be able to read these records at the same time to tackle a bigger
problem in one of my applications. I can easily solve this problem by switching to a "real" database system but this is unfortunately not possible.
If the problem above is solved in any other way, I am still really interested in how to tell Access to use different locking types (from OleDb/C#).
戈德·汤普森写道:
Have you tried using an OleDbTransaction with System.Data.IsolationLevel.ReadUncommitted?
Locking and transaction isolation levels are interrelated. For
example, the description for IsolationLevel.ReadUncommitted says that
"no shared locks are issued and no exclusive locks are honored" (ref:
here). I have not seen any options in System.Data.OleDb that seem to
match the adLockOptimistic option for (COM) ADO Recordset objects.
我正在通过 C# 中的 OleDb 与 Access 2010 通信。 如何设置 锁定类型 以使用来自 C# 的 乐观锁定 ?
如果有人想知道,我正在使用此连接字符串连接到我的 Access 数据库:
// Set the data source string.
_sqlCon = new OleDbConnection(
String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True", databasePath)
);
更新 #0
我从 Microsoft MSDN 网站 (https://msdn.microsoft.com/en-us/library/ee252458(v=bts.10).aspx) 的 ADO 中找到了一些关于 adLockOptimistic
的信息,这些信息可能完全不相关,因为我使用的是 OLE.
更新 #1
我尝试将以下内容添加到连接字符串中:
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;LockType=3;"
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;Lock Type=3;"
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;LockType=adLockOptimistic;"
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;Lock Type=adLockOptimistic;"
所有这些都会导致以下异常:
Could not find installable ISAM.
我预计它不会起作用,但是,嘿,谁知道你是否不尝试。
更新 #2
如果可以在我的 Access 数据库中定义此 属性,该解决方案也非常好!但是,这应该是数据库设置而不是客户端特定设置,并且 如果 可以从 C# 中实现,该方法符合我的偏好。
上下文信息:
I am doing a concurrency stress-test on my Access database (over a network). I have about 20+ clients (little C# programs) that are reading the same record from the same table as fast as possible for each client. This gives a lot of
database is in 'Admin' mode by ..
exceptions and I catch these exceptions in my little C# client. I want to be able to read these records at the same time to tackle a bigger problem in one of my applications. I can easily solve this problem by switching to a "real" database system but this is unfortunately not possible.If the problem above is solved in any other way, I am still really interested in how to tell Access to use different locking types (from OleDb/C#).
戈德·汤普森写道:
Have you tried using an OleDbTransaction with System.Data.IsolationLevel.ReadUncommitted?
Locking and transaction isolation levels are interrelated. For example, the description for IsolationLevel.ReadUncommitted says that "no shared locks are issued and no exclusive locks are honored" (ref: here). I have not seen any options in System.Data.OleDb that seem to match the adLockOptimistic option for (COM) ADO Recordset objects.