Windows Process Hanging in WinApp

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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

Dear Patrik,

The differences I between console and winforms application should not
caus the Process to hung.

The fundamental differences are:
Console applications run under the Console subsystem, and have their
own IO channels.
Creating UI under Console applications should not do any problem.

So there are no differences that should affect what you are trying to
do, especially when using ShellExecute.

Is there any Form created in your code?
How do you start the process (What triggers it?)

Moty
 
For starters, I suggest that you dont call WaitForExit. Rather, you
can get the handle of the process (by using the Handle property), &
use that for calling WaitOne so that you have a timeout mechanism in-
case the process actually hangs.

Does it work, if you just set the FileName & command line arguments &
not set any of the other params?

e.g.

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

Also, once you call WaitForExit, does the SqlCmd process show up in
the Task Manager?

-Dennis
 
Back
Top