.Net下执行sqlcmd的方法
2022-11-12 09:54:11
内容摘要
这篇文章主要为大家详细介绍了.Net下执行sqlcmd的方法,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!如下代码:被的调用方法:
代码如下:
文章正文
这篇文章主要为大家详细介绍了.Net下执行sqlcmd的方法,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
如下代码:被的调用方法:代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <code> 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; } </code> |
代码如下:
1 2 3 4 5 6 7 | <code> 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); } </code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <code> 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/' ) </code> |
注:关于.Net下执行sqlcmd的方法的内容就先介绍到这里,更多相关文章的可以留意
代码注释