c#:
string tmpFile = Path.GetTempFileName();
string argument = string.Format(@" -S {0} -d {1} -i ""{2}"" -o ""{3}""",
ServerName, DatabaseName, fileName, tmpFile);
// append user/password if not use integrated security
if (!connection.IsIntegratedSecurity)
argument += string.Format(" -U {0} -P {1}", User, Password);
var process = Process.Start("sqlcmd.exe", argument);
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start();
while (true)
{
// wait for the process exits. The WaitForExit() method doesn't work
if (process.HasExited)
break;
Thread.Sleep(500);
}
vbnet:
Dim tmpFile As String = Path.GetTempFileName
Dim argument As String = String.Format(" -S {0} -d {1} -i """"{2}"""" -o """"{3}""""", ServerName, DatabaseName, fileName, tmpFile)
' append user/password if not use integrated security
If Not connection.IsIntegratedSecurity Then
argument = (argument + String.Format(" -U {0} -P {1}", User, Password))
End If
Dim process As var = Process.Start("sqlcmd.exe", argument)
process.StartInfo.UseShellExecute = false
process.StartInfo.CreateNoWindow = true
process.Start
While true
' wait for the process exits. The WaitForExit() method doesn't work
If process.HasExited Then
Exit While
End If
Thread.Sleep(500)
End While
沒有留言:
張貼留言