zoukankan      html  css  js  c++  java
  • .Net 执行sqlcmd

    遇到这样一个问题:程序实现创建sqlserver 端点,添加webmethod,删除webmethod,如果直接用ado.net 的sqlhelp 实现,总是报错,后来想到了用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不知能否运行?

  • 相关阅读:
    CSS样式
    hdu 6038 Function
    hdu 6034 Balala Power!
    错排公式 (递推)
    快速求排列组合 lucas定理
    fzu Problem 2275 Game(kmp)
    HDU 3635 Dragon Balls(并查集)
    HDU 3172 Virtual Friends(map+并查集)
    hdu 2818 Building Block(并查集,有点点复杂)
    hdu 1272 小希的迷宫(并查集)
  • 原文地址:https://www.cnblogs.com/staid/p/1755877.html
Copyright © 2011-2022 走看看