How to read the output/error of osql

callinnn

New member
Joined
Sep 18, 2008
Messages
4
Programming Experience
Beginner
Hi All,

i m trying to execute the sql script through vb.net

I m using the following code to get the output of execution of the osql as follows

VB.NET:
sCommand = "osql -b -n -S " & sServernme & " -U " & sUser & " -P " & sPwd & " -d " & sDBName & " -i " & sPath & filename

'Note : The file is a .sql file

Dim si As ProcessStartInfo = New ProcessStartInfo("cmd.exe")
                    ' Redirect both streams so we can write/read them.
                    si.RedirectStandardInput = True
                    si.RedirectStandardOutput = True
                    si.RedirectStandardError = True
                    si.UseShellExecute = False
                    ' Start the procses.
                    Dim p As Process = Process.Start(si)
                    ' Issue the dir command.
                    p.StandardInput.WriteLine(sCommand)
                    ' Exit the application.
                    p.StandardInput.WriteLine("exit")
                    ' Read all the output generated from it.
                    Dim output As String = p.StandardOutput.ReadToEnd

I get the output as string

if i execute the same command through cmd it runs successfully and i get nothing as output

But when i run it through vb.net it shows the prompt and the command that i have given, in output string

if there is no error i expect output string to be blank, so that i can trace up that there is no error

Pls help

Regards
Sanjay
 
Why don't you run osql.exe as process instead of cmd.exe?
 
Thank u so much

i have tried placing osql.exe in place of cmd.exe

But i get the following string in the variable output

"Error: No user selected. Try with -U or -E switches"

Regards,
Sanjay
 
You have to put all arguments in Arguments property. It should be something like this:
VB.NET:
Dim filepath As String = IO.Path.Combine(path, filename)
psi.Arguments = String.Format("-b -n -S {0} -U {1} -P {2} -d {3} -i {4}", servername, user, pwd, dbname, filepath)
 
Thanks,

But i m not able to get, how to use the above code into my code so that i can achieve the results,

Pls help

Regards,
Sanjay
 
"psi" means ProcessStartInfo, is that what you don't understand? You were using PSI in first post so I didn't find it necessary to explain it.
 
Back
Top