任何人都可以提供 SQLite“SetTimeout”的 C# 示例吗?

发布于 2024-09-06 23:40:09 字数 760 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

椵侞 2024-09-13 23:40:09

就像你说的, 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.

对风讲故事 2024-09-13 23:40:09

SetTimeout 是 NHibernate 查询接口 ICriteriaIQuery 的成员。

例子:

using (var session = sessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
    var items = session.CreateQuery("select something complex from a big table")
                       .SetTimeout(600) // 10 minutes
                       .List();
    tx.Commit();
}

SetTimeout is a member of both NHibernate query interfaces, ICriteria and IQuery.

Example:

using (var session = sessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
    var items = session.CreateQuery("select something complex from a big table")
                       .SetTimeout(600) // 10 minutes
                       .List();
    tx.Commit();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文