简体   繁体   English

使用多线程的SQL Server数据库更新

[英]SQL Server Database Update using Multithreading

I have a requirement to update 20 tables in a SQL Server database in a C# application. 我需要在C#应用程序中更新SQL Server数据库中的20个表。 For better performance, I am planning to use multiple threads for updating tables. 为了获得更好的性能,我计划使用多个线程来更新表。 Could anybody refer any example link which gives idea for this kind of operation? 任何人都可以参考任何给出这种操作思路的示例链接吗?

Also, as per my understanding, if I use multi threading, then I have to use different connection object for each thread. 另外,根据我的理解,如果我使用多线程,则必须为每个线程使用不同的连接对象。 In that case, how I can put multiple threads in a single transaction, which are basically using different connection objects? 在那种情况下,如何将多个线程放入单个事务中,这些线程基本上使用不同的连接对象?

使用TPL(任务并行库),下面是示例http://safeery2k.wordpress.com/2013/09/17/ado-net-using-tpl/

20 tables to update at once is pretty crazy. 一次更新20个表非常疯狂。

If 20 stored procedures is the ONLY way to do what needs to get done then create one more stored procedure that will call the 20 stored procedures for you and simply use this stored procedure. 如果只有20个存储过程是完成所需工作的唯一方法,那么再创建一个存储过程,它将为您调用20个存储过程,并简单地使用此存储过程。

This way if an error/exception occurs you will be able to rollback the mods AND it is now contained in one location - nice and easy (all things considered). 这样,如果发生错误/异常,您将能够回滚该mod,并且现在将其包含在一个位置-简单又方便(考虑了所有因素)。

I'm very glad I don't have to deal with the situation you're in with this one! 我很高兴我不必处理您遇到的这种情况! Good luck with this! 祝你好运!

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

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