Windows mobile 紧凑框架 SqlCeConnection

发布于 2024-08-24 15:29:14 字数 117 浏览 1 评论 0原文

我听说最好在应用程序启动时打开一个连接,并在应用程序关闭时关闭它。

多个连接会出现什么类型的问题?

有没有文章指出建立一个连接是最佳做法?

您对 sql ce 的体验如何?

I'm hearing that is better to have one connection open upon app start up and closing it when the app shuts down.

What kind of issue can occur having multiple connections ?

Any articles out there that it is best practices to have one connection?

What are your experience with sql ce?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

居里长安 2024-08-31 15:29:14

在我们的 SQL CE 3.5 / Compact Framework 3.5 应用程序中,我们在启动时打开一个连接,并保持它打开状态,直到应用程序关闭。应用程序中几乎每个用户交互都需要数据库,并且保持连接打开比按需打开和关闭连接更快。

所有数据更新均在事务中执行。我们使用 提交 事务a href="http://msdn.microsoft.com/en-US/library/system.data.sqlserverce.commitmode.aspx" rel="nofollow noreferrer">CommitMode.Immediate 选项。这可确保数据更改立即刷新到文件,从而最大限度地减少数据丢失的可能性。

In our SQL CE 3.5 / Compact Framework 3.5 application, we open a connection at startup and keep it open until the application is closed. The database is required on almost every user-interaction in the application and keeping the connection open is faster than opening and closing it on demand.

All data updates are performed in transactions. We Commit the transactions using the CommitMode.Immediate option. This ensures that data changes are immediately flushed to the file, minimising the potential for data loss.

秋凉 2024-08-31 15:29:14

这确实取决于。就性能而言,如果始终存在与数据库的实时连接,SQL CE 效果最佳,因为引擎不必在每次连接时构建所有内容。

然而,只有一个连接会导致数据延迟刷新到文件,并且在发生灾难性故障时更有可能丢失或损坏数据。

我倾向于在应用程序启动时打开与数据库的“虚拟”连接,并始终打开该连接,但很少或从未实际使用过。如果您愿意的话,这可以使发动机保持“准备就绪”。然后,对于实际的数据访问,我使用单独的连接并根据我正在执行的活动管理状态,通常在多个查询中保持打开状态(如果愿意,可以称为伪事务),但不会无限期地保持打开状态。

It really depends. For performance, SQL CE works best if there is always a live connection to the database, as the engine doesn't have to build up everything every time you connect.

Having a single connection, however, leads to lazy flushiong of data to the file, and a higher likelihood of data loss or corruption in the event of a catastrophic failure.

I tend to open a "dummy" connection to the database at app startup and have that connection always open but rarely or never actually used. This keeps the engine "primed" if you will. THen for actual data access I use a separate connection and manage state based on what activity I'm doing, typically leaving it open across multiple queries (a pseudo transaction if you will), but not leaving it open indefinitely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文