SqlCommand对象的prepare方法在什么情况下有用?
有谁知道 ADO.NET SqlCommand 对象的准备方法在什么情况下有用?
Does any body know that in what situations the prepare method of an ADO.NET SqlCommand Object is useful?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们谈论的是 SqlCommand,它意味着 Microsoft SQL Server。据我所知SQL Server一直支持它。
但尚不清楚它是否有任何用处。我还没有找到真正了解的人。许多人声称它没有任何用处,并且没有可测量的性能差异。我想以某种方式看到证据。
在另一个数据库(使用 FbCommand 对象的 Firebird)上,我知道如果您不小心,它可能会导致问题。如果您准备了一份声明但从未使用它,则交易将永远保持开放状态。我们必须从 Firebird 代码中删除所有准备工作。我们已经习惯于准备任何可能被多次执行的事情。
We are talking about a SqlCommand which implies Microsoft SQL Server. As far as I know SQL Server has always supported it.
It's not clear however if it does anything useful. I've yet to find anyone who really knows. A lot of people claim it does nothing useful and there is no measurable performance difference. I'd like to see evidence one way or another.
On another database (Firebird using an FbCommand object) I know it can cause problems if you are not careful. If you prepare a statement but then never use it a transaction gets held open forever. We had to remove all prepares from our code for Firebird. We had been in the habit of preparing anything that might get executed multiple times.
通常,现代数据库会缓存命令和查询计划,但通过准备好查询或命令,您仍然可以节省一些时间。
Normally modern databases cache commands and query plans but by having your queries or commands preprepared you can still save some time.