Problem starting a process (sqlcmd.exe)

B

Bogdan

Hi,

I'm trying to run sqlcmd.exe from a C# console app. The code is as follows:

[...]
private string serverName = @"dev16\SQLExpress";
[...]
private void ExecuteSqlScript(string databaseName, string inputFileName)
{
string tempPath = System.IO.Path.GetTempPath();
string outputFileName = "sqlcmd.out";

using (Process process = new Process())
{
try
{
process.StartInfo.FileName = "sqlcmd.exe";
process.StartInfo.Arguments = string.Format(@"-l 60 -t 60 -b -S
""{0}"" -d ""{1}"" -i ""{2}"" -o ""{3}""", this.serverName, databaseName,
inputFileName, outputFileName);
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = tempPath;
process.Start();
process.WaitForExit();
process.Close();
}
catch (Exception ex)
{
throw (ex);
}
}
}


When I run the above code, the sqlcmd utility displays the following error:
Sqlcmd: '-S': Unexpected argument. Enter '-?' for help.

I check the 'Arguments' property in the debugger and everything looked fine.
I have no problem executing sqlcmd.exe 'manually' from Command Prompt - also
from the temp folder with identical arguments. I can also execute it from a
C/C++ native app using Win32 APIs.

I mainly work with native C/C++ and only occasionally with C#/.NET. I must
be missing something obvious (I based the above code on a sample found with
google's help).

I'd appreciate _any_ suggestions.

Thanks,
Bogdan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top