EXEC master..xp_cmdshell 'osql -Svaio -Usa -Pzaassds1 -ic:\MySQl.sql -n'
http://www.dotnet247.com/247reference/msgs/26/131475.aspx
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=561&lngWId=10

解决方案 »

  1.   

    你可以启动SQL Server使用工具osql.exe,将脚本文件作为参数传递就可以了。
    string szCurrentPath=System.IO.Directory.GetCurrentDirectory().ToString();
    string szSQLFile=szCurrentPath+"\\test.sql";
    string szFileName=@"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql.exe";string szArguments="-S localhost -U sa -P  -i"+szSQLFile;System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo(szFileName,szArguments);
    processStartInfo.UseShellExecute = false;
    processStartInfo.CreateNoWindow = true;
    processStartInfo.RedirectStandardOutput = true;
    processStartInfo.RedirectStandardError = true;
    System.Diagnostics.Process process = System.Diagnostics.Process.Start(processStartInfo);
      

  2.   

    System.Diagnostics.Process Process1 =new System.Diagnostics.Process();
    Process1.StartInfo.FileName = "osql ";
    Process1.StartInfo.Arguments = @" /E /S /n /i "+spname+".sql";
    Process1.Start();
    while (Process1.HasExited)
    {
        continue;
    }
    Process1.Close();