c# - 通过 OleDb (C#) 将 Access 2010 记录锁定设置为乐观锁定

标签 c# ms-access-2010 oledb

我在 C# 中通过 OleDbAccess 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

我找到了一些关于 adLockOptimistic 的信息来自 Microsoft MSDN 网站 ( https://msdn.microsoft.com/en-us/library/ee252458(v=bts.10).aspx ) 上的 ADO,这可能完全不相关,因为我使用的是 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 (C#) 将 Access 2010 记录锁定设置为乐观锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28692287/

相关文章:

c# - 检查列表中的下一个最高/最低值并选择该项目

ms-access - 如何计算表中的字段数?

vba - 从选定的列表框在 Access 子表单中显示查询

c# - 有人知道如何使用 C# 从 oledb 驱动程序中删除 pack foxpro 数据

csv - 使用 Jet Oledb 读取文本文件,标题关闭(HDR=否)

sql-server - “Microsoft.ACE.OLEDB.16.0”提供程序未在本地计算机上注册。 (系统.数据)

c# - MVVM – UWP 的层次结构和导航隐式绑定(bind)

c# - 免费的 PDF 操作库或代码?

c# - 一个程序集中的多个服务。安装程序如何知道要安装和启动哪个服务?

sql - 在 SQL 查询中将日期舍入到日期