Groups | Blog | Home
all groups > sql server programming > may 2007 >

sql server programming : Windows Process Hanging in WinApp


Pratik Mehta
5/20/2007 11:11:01 PM
Hi All,

I am trying to run following command to execute SQLCmd command in a seperate
process in a windows application. This SQLCmd command is intended to execute
SQL batch statements against the sql server database.

Process process = new Process ( );
process.StartInfo.Arguments = "-S psi-pc0183\\sql2k5 -U sa -P pwd -d DBName
-i CreateUDFs.sql -V1 -m1";
process.StartInfo.CreateNoWindow = false;
process.StartInfo.ErrorDialog = false;
process.StartInfo.FileName = "SqlCmd";
process.StartInfo.RedirectStandardOutput = false;
process.StartInfo.RedirectStandardError = false;
process.StartInfo.ErrorDialog = false;
process.StartInfo.UseShellExecute = true;
process.StartInfo.WorkingDirectory =
@"D:\CD\CD_50\Build\EplSetup\DataBaseSetup";
process.Start ( );
process.WaitForExit ( );

But, It is not responding. it is just hanging without any response
indefinitely. However, I am getting the desired result and process is working
properly in Console application.

Kindly suggest what should be the cause of this and any resolution of this
problem.

I am thankful to you in advance for whatever solution or workarounds you
have in your mind.

thanks again,
Pratik
Dan Guzman
5/21/2007 5:56:10 AM
[quoted text, click to view]

I think your code is ok but maybe the dash is the server name is causing a
problem. You might try enclosing the server argument in quotes:

process.StartInfo.Arguments = "-S \"psi-pc0183\\sql2k5\" -U sa -P pwd -d
DBName

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]
Mimetis
5/21/2007 8:15:07 AM
Try this :

process.Start ( );

process.StandardOutput.ReadToEnd();

process.WaitForExit ( );

process.Close();


Hope this helps

Sebastien Pertus

http://www.bewise.fr
AddThis Social Bookmark Button