How to send multiple commands to SQL Server 2008 w

2019-08-05 18:26发布

I want to send multiple parametrized update, insert and delete commands to a sql server database in one round trip. I've looked at sqlbulkcopy but that appears to only work with one mapping/table/statement at a time. 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. I attempted looking through the nhibernate source but it wasn't immediately clear how it was doing the batching. 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.

2条回答
姐就是有狂的资本
2楼-- · 2019-08-05 19:06

Set CommandType to Text, and separate your commands with semicolons. You end up with one giant command, whose parameter names you may need to generate programmatically (to avoid conflicts).

查看更多
Explosion°爆炸
3楼-- · 2019-08-05 19:18

if i am not wrong SqlCommandBuilder will help you :) . SqlCommandBuilder

查看更多
登录 后发表回答