C#中执行Sql文件

C#中执行SQL Server脚本
private void btnDemo_Click(object sender, EventArgs e)  
{  
     // 调用sqlcmd  
    ProcessStartInfo info = new ProcessStartInfo("sqlcmd", @" -S .\MSSQLSERVER -i C:\backup.sql");  
    //禁用OS Shell  
    info.UseShellExecute = false;  
    //禁止弹出新窗口  
    info.CreateNoWindow = true;  
    //隐藏windows style  
    info.WindowStyle = ProcessWindowStyle.Hidden;  
    //标准输出  
    info.RedirectStandardOutput = true;  
  
    Process proc = new Process();  
    proc.StartInfo = info;  
    //启动进程  
    proc.Start();  
}  

你可能感兴趣的:(数据库)