C# System.Data.SQLite 设计器代码

发布于 2024-08-16 17:22:11 字数 244 浏览 2 评论 0原文

我一直在使用 Visual Studio 2008 中的 SQLite 设计器,我注意到当我使用生成的插入/更新语句时,它们运行得非常慢。

示例:我有一个包含 4 列和 5700 行的数据表,将数据插入数据库表需要大约 5 分钟

但是,我使用参数和单个事务编写了自己的数据库连接和插入方法,并且插入了相同的 5700 行不到 1 秒。

为什么生成的代码如此慢以及使用它有什么好处?

谢谢。

内森

I've been messing around with the SQLite Designer in Visual Studio 2008 and I have noticed that when I use the generated Insert/Update statements they run extremely slow.

Example: I have a data table with four columns and 5700 rows it took ~5 mins to insert the data into the database table

However, I wrote my own database connection and insert methods using parameters and a single transaction and the same 5700 rows were inserted in under 1 second.

Why is the generated code so slow and what is benefit to even using it?

Thanks.

Nathan

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

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

发布评论

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

评论(2

不如归去 2024-08-23 17:22:11

我读到 SQLite 中的默认行为是将每个 Insert 语句包装在事务中,我认为这解释了您所看到的行为。当 SQLite 引擎创建 Insert 语句时,它需要很长时间,而当您编写 sql 时,它运行得非常快。

http://www.sqlite.org/faq.html#q19

I've read that the default behavior in SQLite is to wrap each Insert statement in a Transaction, which I think explains the behavior you are seeing. When the SQLite Engine creates the Insert statements it takes a long time and when you write the sql it runs very quickly.

http://www.sqlite.org/faq.html#q19

余厌 2024-08-23 17:22:11

如果我理解正确的话,插入语句是在代码隐藏中构建的,并且执行需要很长时间是正常的...它必须被编译,处理成CLR等。如果您在数据库上使用存储过程花费更少的时间,因为当您从代码隐藏调用该过程时已经完成了这些步骤。直接使用数据库中的过程总是比在代码隐藏中编写它们更好更快。

if i nderstood correctly that insert statement is built in code-behind and it's normal that it would take a long time to execute... it has to be compiled, processed turned into CLR etc. If you use a stored procedure on the database it takes less time cause that procedure when you call it from code-behind has already been through these steps. It's always better and faster to use procedures directly from the databae than wright them in code-behind.

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