惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
D
DataBreaches.Net
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
Recent Announcements
Recent Announcements
The Register - Security
The Register - Security
S
Secure Thoughts
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 最新话题
V2EX - 技术
V2EX - 技术
腾讯CDC
GbyAI
GbyAI
G
Google Developers Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
Microsoft Security Blog
Microsoft Security Blog
Jina AI
Jina AI
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
Help Net Security
Help Net Security
K
Kaspersky official blog
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
AI
AI
MongoDB | Blog
MongoDB | Blog
Scott Helme
Scott Helme
J
Java Code Geeks
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
H
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
S
Security Affairs
TaoSecurity Blog
TaoSecurity Blog
The GitHub Blog
The GitHub Blog
Hacker News: Ask HN
Hacker News: Ask HN
Martin Fowler
Martin Fowler
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI

博客园 - edobnet

phonegap 开发初探 .net C# ADC接口中DES加密算法 阿里软件接口开发基础(淘宝网) C# SQL 2005自动备份文件删除 短信猫与中国移动CMPP2。0收发短信实例 针对sql 2005优化的高性能分页存储过程 .net framework 2.0以上修改config配制更容易 - edobnet LinQ操作汇总(From CSharpSamples) 远程注册表读取,与多线程池的应用. 使用JAVASCRIPT控制,IFAME的内容,从而使用投票点击等功能 ADSL自动断拨号类 类拟EXCEL表格锁定的功能的实现! - edobnet - 博客园 线程,线程数控制! sql Server 2000 分区视图的运用 利用.Net 线程池提高应用程序性能. google 中国编程大赛测试题,及自己的解答 触发器在增量同步数据的运用. 进程服务编写,与启动停止控制 js异步XMLhttpPost,并带有,等待显示,防正,XMLhttpPost请求时间过来,而使浏览器死掉! - edobnet - 博客园
通过OSQL命令执行SQL SERVER批SQL
edobnet · 2008-01-25 · via 博客园 - edobnet

通过System.Data.SqlClient命名空间只能执行单条SQL,或多个内容中间用;分开,不能执行类似等命令,有没有一种方法能类似查询分析器一样执行一些批命令呢,答案是通过OSQL来执行。
OSQL详细用法:http://technet.microsoft.com/zh-cn/library/ms162806.aspx
通地进程来调用:

    /// <summary>
        
/// 执行OSQL命令
        
/// </summary>

        public static  void ExcuteOsqlCmd(string cmd, string errorFile, string filePath)
        
{
            System.Diagnostics.Process p 
= new System.Diagnostics.Process();

            p.StartInfo.FileName 
= "osql";
            p.StartInfo.Arguments 
= cmd;
            p.StartInfo.UseShellExecute 
= false;

            p.StartInfo.RedirectStandardError 
= true;
            p.StartInfo.CreateNoWindow
=true;
            p.Start();
            p.WaitForExit();
            
//p.Close();
            int exitCode = p.ExitCode;
            
if (exitCode != 0)
            
{
                StreamReader sr 
= new StreamReader(errorFile, System.Text.Encoding.Default);
                
string all = sr.ReadToEnd();
                sr.Close();
                
//ExcuteOtherCmd(string.Format("notepad \"{0}\"", errorFile));
                throw new StepException(all);
            }


        }

调用如下:
string comm = string.Format(" -U {5} -P {0} -S {1} -d {2} -b -e  -i \"{3}\" -o \"{4}\"", pass,
                                         conn.DataSource,
                                         conn.Database,
                                         FilePath, errorFile,user);
Process.ExcuteOsqlCmd(comm, errorFile, FilePath);//直接执行一个SQL文件,路径为FilePath