您现在的位置是:网站首页> 编程资料编程资料
.Net下执行sqlcmd的方法_MsSql_
2023-05-26
488人已围观
简介 .Net下执行sqlcmd的方法_MsSql_
如下代码:
被的调用方法:
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不知能否运行?
被的调用方法:
复制代码 代码如下:
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不知能否运行?
相关内容
- SqlServer下通过XML拆分字符串的方法_MsSql_
- Sqlserver 常用日期时间函数_MsSql_
- SQLServer中SELECT语句的执行顺序_MsSql_
- sqlserver 存储过程分页代码第1/2页_MsSql_
- 在SQLServer上查看SQL语句的执行时间的方法_MsSql_
- 当恢复sqlserver bak文件时,原始的用户无法删除的解决方法_MsSql_
- 数据库中经常用到的操作和管理数据库的语句总结第1/2页_MsSql_
- 删除Table表中的重复行的方法_MsSql_
- distinct 多列问题结合group by的解决方法_MsSql_
- SQL中函数 replace 的参数1的数据类型ntext无效的解决方法_MsSql_
