加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

.Net下执行sqlcmd的方法

发布时间:2020-12-12 07:56:23 所属栏目:MsSql教程 来源:网络整理
导读:感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧! 如下代码: 被的调用方法: 代码如下: public static string ExeCommand(string commandText) { Process p = new Process(); p.StartInfo.FileName = cmd.exe; p.StartInfo.UseShellExe

感兴趣的小伙伴,下面一起跟随编程之家 52php.cn的小编两巴掌来看看吧!

如下代码:
被的调用方法:

代码如下:

 
public static string ExeCommand(string commandText) 
{ 
Process p = new Process(); 
p.StartInfo.FileName = "cmd.exe"; 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.RedirectStandardInput = true; 
p.StartInfo.RedirectStandardOutput = true; 
p.StartInfo.RedirectStandardError = true; 
p.StartInfo.CreateNoWindow = true; 
string strOutput = null; 
try 
{ 
p.Start(); 
p.StandardInput.WriteLine(commandText); 
p.StandardInput.WriteLine("exit"); 
strOutput = p.StandardOutput.ReadToEnd(); 
p.WaitForExit(); 
p.Close(); 
} 
catch (Exception e) 
{ 
strOutput = e.Message; 
} 
return strOutput; 
} 

调用方法:

代码如下:

 
protected void Button1_Click(object sender,EventArgs e) 
{ 
string sqlQuery = "sqlcmd.exe -U sa -P 123 -S 20100330-0922 -d test -i c:1.sql"; 
string strRst = ExeCommand(sqlQuery); 
} 

1.sql文件

代码如下:

 
use master 
go 
CREATE ENDPOINT Orders_Endpoint6 
state=started 
as http( 
path='/sql/orders6',AUTHENTICATION=(INTEGRATED),ports=(clear) 
) 
for soap( 
WebMethod 'CustOrdersOrders'( 
name='test.dbo.GetAlltb12' 
),wsdl=default,database='test',namespace='http://mysite.org/' 
) 

BS程序如果执行的话,客户端不安装sqlcmd不知能否运行?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读