【问题标题】:SQLCMD Mode run with .net windows applicationSQLCMD 模式与 .net windows 应用程序一起运行
【发布时间】:2018-10-29 06:42:49
【问题描述】:

我想通过 .net windows 应用程序运行 SQLCMD.EXE,我该如何实现呢?

【问题讨论】:

    标签: .net sql-server windows sqlcmd


    【解决方案1】:

    您必须在using System.Diagnostics; 下使用ProcessStartInfo

    // Calls the sqlcmd
    ProcessStartInfo info = new ProcessStartInfo("sqlcmd", @" -S .\sqlexpress -i C:\YourFileName.sql");
    
    //  Indicades if the Operative System shell is used, in this case it is not
    info.UseShellExecute = false;
    
    //No new window is required
    info.CreateNoWindow = true;
    
    //The windows style will be hidden
    info.WindowStyle = ProcessWindowStyle.Hidden;
    
    //The output will be read by the starndar output process
    info.RedirectStandardOutput = true;
    
    Process proc = new Process();
    
    proc.StartInfo = info;
    
    //Start the process
    proc.Start();
    

    【讨论】:

    • 感谢您的回复。我想在其中传递参数(当调用 SQLCMD 调用时)。那么,在进程信息中作为参数传递?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多