.Net下执行sqlcmd的方法

前端之家收集整理的这篇文章主要介绍了.Net下执行sqlcmd的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如下代码
被的调用方法
<div class="codetitle"><a style="CURSOR: pointer" data="63653" class="copybut" id="copybut63653" onclick="doCopy('code63653')"> 代码如下:

<div class="codebody" id="code63653">
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;
}

调用方法
<div class="codetitle"><a style="CURSOR: pointer" data="55367" class="copybut" id="copybut55367" onclick="doCopy('code55367')"> 代码如下:
<div class="codebody" id="code55367">
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文件
<div class="codetitle"><a style="CURSOR: pointer" data="33340" class="copybut" id="copybut33340" onclick="doCopy('code33340')"> 代码如下:
<div class="codebody" id="code33340">
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不知能否运行?

.Netsqlcmd

猜你在找的MsSQL相关文章