任何人都可以提供 SQLite“SetTimeout”的 C# 示例吗?
我在 Fluent NHibernate 项目上使用 SQLite(system.data.sqlite v. 1.0.60.0)。
我有一个程序写入数据库,另一个程序从数据库读取。有时,我会遇到 SQLITE_BUSY 异常,我需要解决这个问题。
我发现了一些对 sqlite_busy_timeout 的 Google 引用,这(如果我理解正确的话)将导致 SQLite 在抛出异常之前重试。这可能足以满足我的需求。
但是,这似乎不在 system.data.sqlite 程序集中。
当我使用对象浏览器搜索 SetTimeout 时,我得到了两次结果:
System.Data.SQLite.SQLite3.SetTimeout(int)
System.Data.SQLite.SQLiteBase.SetTimeout(int)
但我似乎无法在我的代码中使用它们 - 它们没有出现在 Intellisense 中,并且 VS2008 显示SQLite3 的红色下划线,带有消息“无法在此处访问内部类”。
谁能给我一个示例(C# 语言)来显示此方法的确切语法?
或者这是否是正确的方法?我可能可以在代码中检查 SQLITE_BUSY,但也没有找到任何很好的示例来演示该方法。
最后,Fluent NHibernate 或 NHibernate 是否有任何机制来提供对 SQLite 数据库的简单共享访问?
I'm using SQLite (system.data.sqlite v. 1.0.60.0) on a Fluent NHibernate project.
I have one program that writes to the DB, and another that reads from it. Occasionally, I get SQLITE_BUSY exceptions, and I need to fix this.
I found several Google references to sqlite_busy_timeout, which (if I understand correctly) will cause SQLite to re-try before throwing the exception. This would probably be sufficent for my needs.
However, this does not appear to be in the system.data.sqlite assembly.
When I search for SetTimeout using the Object Browser, I get two hits:
System.Data.SQLite.SQLite3.SetTimeout(int)
System.Data.SQLite.SQLiteBase.SetTimeout(int)
but I can't seem to use them in my code - they don't show up in Intellisense, and VS2008 shows a red underline for SQLite3, with the message "Can't access internal class here".
Can anyone give me a sample (in C#) that shows the exact syntax for this method?
Or is this even the right approach? I could probably check for SQLITE_BUSY in my code, but have not found any good examples demonstrating that approach either.
Finally, do Fluent NHibernate or NHibernate have any mechanisms to provide simple shared access to a SQLite database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就像你说的, SetTimeout() 是内部的,因此您(或 NHibernate)无法调用它。该方法仅包装
sqlite_busy_timeout
并抛出异常,您绝对不想在应用程序代码中使用这些不安全的方法。根据此,SQLite 提供程序应重试 30 秒。
Just like you said, SetTimeout() is internal, so you (or NHibernate) can't call it. The method only wraps
sqlite_busy_timeout
and throws, and you definitely don't want to use those unsafe methods in your application code.According to this, the SQLite provider should retry for 30 seconds.
SetTimeout
是 NHibernate 查询接口ICriteria
和IQuery
的成员。例子:
SetTimeout
is a member of both NHibernate query interfaces,ICriteria
andIQuery
.Example: