OSQL + not responsing.

G

gopal

Hi

I am running a OSQL utility from my console application . iam trying to
install a huge SQL file of 5MB, i debugged my code and the application
is not responding at the following line of code


psi.FileName =
"osql.exe";
psi.Arguments = osqlArgs;
psi.UseShellExecute=false;
psi.CreateNoWindow=true;
psi.RedirectStandardOutput=true;
Process proc = Process.Start (psi);
proc.WaitForExit(); ///// NOt Responding here
{or}
proc.WaitForExit() //Not
Responding
int iSuccess = proc.ExitCode;


Any one please give some possible clue to this?


Regards
JP
 
W

Willy Denoyette [MVP]

| Hi
|
| I am running a OSQL utility from my console application . iam trying to
| install a huge SQL file of 5MB, i debugged my code and the application
| is not responding at the following line of code
|
|
| psi.FileName =
| "osql.exe";
| psi.Arguments = osqlArgs;
| psi.UseShellExecute=false;
| psi.CreateNoWindow=true;
| psi.RedirectStandardOutput=true;
| Process proc = Process.Start (psi);
| proc.WaitForExit(); ///// NOt Responding here
| {or}
| proc.WaitForExit() //Not
| Responding
| int iSuccess = proc.ExitCode;
|
|
| Any one please give some possible clue to this?
|
|
| Regards
| JP
|

Calling:
proc.WaitForExit();
forces the caller to wait until the osql.exe process terminates, but this
ain't gonna happen unless you send a "quit" command to osql.

Willy.
 
W

Willy Denoyette [MVP]

| Hi Willy
|
| Please how can this be done..How to Quit?


You are redirecting stdin and stdout don't you? So you have to pass a "quit"
string to osql's standard input whe done, just like you would do from the
commandline.

...
proc.WaitForExit();
proc.StandardInput.WriteLine ("quit");

Willy.
 
G

gopal

Hi Willy,

Yes, i am rdirecting the std output by giving
psi.RedirectStandardOutput=true;

but i am not redirecting the std input. and i also added the line

proc.StandardInput.WriteLine ("quit"); but still it is not responding

I was debugggng but when the control came over to
proc.StandardInput.WriteLine ("quit");
the applicn stops responsing. Agredd the SQL file as huge file of 5 MB
size and it basically creates a new database

So how can i handle the issue now?

Regards
JP
 
W

Willy Denoyette [MVP]

| Hi Willy,
|
| Yes, i am rdirecting the std output by giving
| psi.RedirectStandardOutput=true;
|
| but i am not redirecting the std input. and i also added the line
|
| proc.StandardInput.WriteLine ("quit"); but still it is not responding
|
| I was debugggng but when the control came over to
| proc.StandardInput.WriteLine ("quit");
| the applicn stops responsing. Agredd the SQL file as huge file of 5 MB
| size and it basically creates a new database
|
| So how can i handle the issue now?
|
| Regards
| JP
|
|
| Willy Denoyette [MVP] wrote:
| > | > | Hi Willy
| > |
| > | Please how can this be done..How to Quit?
| >
| >
| > You are redirecting stdin and stdout don't you? So you have to pass a
"quit"
| > string to osql's standard input whe done, just like you would do from
the
| > commandline.
| >
| > ...
| > proc.WaitForExit();
| > proc.StandardInput.WriteLine ("quit");
| >
| > Willy.
|

Sorry above makes no sense, you need to wait after sending "quit", like so:

proc.StandardInput.WriteLine ("quit");
proc.WaitForExit();

But as I told you before, you are using an interactive utility wrapped by a
batch utility, which is a bad thing, really. Your program needs to act as if
it was an interactive user. That means that in principle you need to
redirect stdout and respond to the command prompts and pôssible error
messages from osql. In your case that would mean you have to wait for the
prompt to return, that is after the sql file has been executed (or when an
error message as returned), and then you can write "quit".
I would suggest you to write a simple C# program using sqlclient to execute
sql scripts instead of using osql the way you do.
Note also that when using sql2005 you should use sqlcmd instead of osql.


Willy.
 

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