1、codeproject上面一个多线程执行sql的库。

开发中常常要执行一些耗时的数据操作,比如update、insert、bulk insert、index creation,

若顺序执行,则操作总时间是每个单独sql的时间之和  为了加快速度,采用线程池异步执行的做法,比如要要create 10个表以及加数据,则可以开10个线程去分别执

 codeproject上库源码地址 http://www.codeproject.com/Articles/29356/Asynchronous-T-SQL-Execution-Without-Service-Broke
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlTypes;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SqlClrLib.Model; namespace ExampleTransaction
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
//开发中常常要执行一些耗时的数据操作,比如update、insert、bulk insert、index creation,
//若顺序执行,则操作总时间是每个单独sql的时间之和,
//为了加快速度,引入异步执行的做法,比如要要create 10个表以及加数据,则可以开10个线程去分别执行
} [Microsoft.SqlServer.Server.SqlProcedure]
public static int SaveWarehouseFinalData(Guid fileDefinitionId)
{
Console.WriteLine("Start");
StoredProcedures.Parallel_Declare(new SqlString("Parallel SaveWarehouseFinalData"));
//Console.WriteLine("Database connection is ... {0}", StoredProcedures.Block.ConnectionString);
//Console.WriteLine("Max threads count is ... {0}", StoredProcedures.Block.MaxThreads);
////ParallelProcedures.Block.IsTransactional = true;
////ParallelProcedures.Parallel_UseTransaction("Serializable");
//依次将存储过程加入到线程池
StoredProcedures.Parallel_AddSql(new SqlString("usp_WarehouseImportSaveToEAV"), new SqlChars(string.Format("usp_WarehouseImportSaveToEAV '{0}'", fileDefinitionId)));
StoredProcedures.Parallel_AddSql(new SqlString("usp_WarehouseImportSaveToAdminHistory"), new SqlChars(string.Format("usp_WarehouseImportSaveToAdminHistory '{0}'", fileDefinitionId)));
StoredProcedures.Parallel_AddSql(new SqlString("usp_WarehouseImportSaveToValResult"), new SqlChars(string.Format("usp_WarehouseImportSaveToValResult '{0}'", fileDefinitionId)));
//执行save操作(此处用的事务,如果不成功会回滚)
int failedCount = StoredProcedures.Parallel_Execute();
//Console.WriteLine("Failed count is ... {0}", failedCount);
ResultItem[] resultItems = (ResultItem[])StoredProcedures.Parallel_GetExecutionResult();
foreach (ResultItem r in resultItems)
{
//Console.WriteLine(r.ToString());
}
//Console.WriteLine("End..."); return failedCount;
} }
}

最新文章

  1. WinFrom窗体始终置顶
  2. Eclipse 常用快捷键 For MAC
  3. java初学者应掌握的30个基本概念
  4. ::after::before清除浮动原理
  5. Windows读取文本文件后的显示过程
  6. 关于Look and Say序列的感想
  7. Unity3D之MeleeWeaponTrail武器轨迹插件的使用
  8. Android学习–Android app 语言切换功能
  9. zabbix 通过smtp 邮件报警
  10. js alert(“”)弹框 自定义样式
  11. Redis学习-Set
  12. 发布一个Python小程序:ManHourCalendar
  13. 高性能伪事务之Lua in Redis
  14. 基本的CRUD操作
  15. angular.identity()
  16. python2.x 与 python3.x的不同
  17. 2017百度软研(C++)
  18. Spring JDBC模版以及三种数据库连接池的使用
  19. 关于Java 软件工程师应该知道或掌握的技术栈
  20. tomcat整体架构

热门文章

  1. python3爬虫爬取煎蛋网妹纸图片(下篇)2018.6.25有效
  2. 训练指南 UVALive - 4043(二分图匹配 + KM算法)
  3. 第1天-html快速入门
  4. ASP.net 资源请求漏洞利用工具PadBuster
  5. English distilled
  6. [Codeforces 30D] Kings Problem
  7. 【递归】【栈】先修课 计算概论(A)/函数递归练习(2)5:布尔表达式
  8. gitk图形界面中文乱码情况
  9. Zookeeper的功能以及工作原理(转)
  10. ASP.NET MVC DropdownList的使用