简体   繁体   English

如何一次往返发送多个命令到SQL Server 2008

[英]How to send multiple commands to SQL Server 2008 with one round trip

I want to send multiple parametrized update, insert and delete commands to a sql server database in one round trip. 我想一次往返发送多个参数化的更新,插入和删除命令到sql服务器数据库。 I've looked at sqlbulkcopy but that appears to only work with one mapping/table/statement at a time. 我看过sqlbulkcopy,但似乎一次只能使用一个映射/表/语句。 I was hoping for some thing a more flexible. 我希望有一些更灵活的方法。 I don't need to get any results from any of the queries (ie: affected row count) but I do want failures to be propagated back to the app layer and so that the transaction can be rolled back. 我不需要从任何查询中获得任何结果(即:受影响的行数),但我确实希望将故障传播回应用程序层,以便可以回滚事务。 Any ideas? 有任何想法吗?

side question: I was also wondering how nHibernate does it, only because it is tried and true and appears to perform well. 附带的问题:我还想知道nHibernate是如何做到的,仅仅是因为它经过尝试并且是真实的,并且表现良好。 I attempted looking through the nhibernate source but it wasn't immediately clear how it was doing the batching. 我试图浏览nhibernate的源代码,但目前尚不清楚它是如何进行批处理的。 I can go back to the source but was hoping someone knew, high level, how it is being handled and could explain it to me. 我可以回到源头,但希望有人能从高水平了解它的处理方式,并可以向我解释。

Set CommandType to Text , and separate your commands with semicolons. CommandType设置为Text ,并用分号分隔命令。 You end up with one giant command, whose parameter names you may need to generate programmatically (to avoid conflicts). 您最终得到一条巨大的命令,您可能需要以编程方式生成其参数名称(以避免冲突)。

if i am not wrong SqlCommandBuilder will help you :) . 如果我没有记错,SqlCommandBuilder会为您提供帮助:)。 SqlCommandBuilder SqlCommandBuilder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM