I am puttng the full code now -
The following program when run, just displays command output without
getting displayed
I tried to get the Database UserName and Password from user, but in
vain.
using System;
using System.Diagnost ics;
using System.IO;
using Microsoft.Win32 ;
using System.Threadin g;
namespace ConsoleApplicat ion3
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
ProcessStartInf o psi = new ProcessStartInf o("osql.exe", "-Usa -Psa");
psi.RedirectSta ndardOutput=tru e;
psi.RedirectSta ndardInput=true ;
psi.RedirectSta ndardError=true ;
psi.UseShellExe cute=false;
psi.CreateNoWin dow=true;
Process proc = Process.Start (psi);
ProcessOutputRe ader por = new ProcessOutputRe ader (proc);
por.Start();
proc.StandardIn put.WriteLine (@"sp_help GO");
proc.StandardIn put.WriteLine() ;
proc.StandardIn put.WriteLine ("mohan");
proc.StandardIn put.WriteLine ("rahul");
class ProcessOutputRe ader
{
Process proc;
public ProcessOutputRe ader (Process proc)
{
this.proc = proc;
}
public void Start()
{
new Thread (new ThreadStart(Rea dAll)).Start();
}
void ReadAll()
{
StreamReader reader = proc.StandardOu tput;
string line;
while ((line = reader.ReadLine ())!=null)
Console.WriteLi ne ("Process output: {0}", line);
}
}
}
}
Ciaran O''Donnell wrote:
This code works for me inside a windows app and a console app in .NET 2.
It writes out:
Error: No user selected. Try with -U or -E switches
Ciaran O'Donnell
"gopal" wrote:
Hi,
I am trying to call the OSQL utility from my C# console application and
i am having problems
i have the following code
In Main method
ProcessStartInf o psi = new ProcessStartInf o("osql","");
psi.RedirectSta ndardInput = false;
psi.RedirectSta ndardOutput = true;
psi.RedirectSta ndardError = false;
psi.CreateNoWin dow = false;
psi.UseShellExe cute = false;
Process pc = Process.Start(p si);
Console.WriteLi ne(pc.StandardO utput.ReadToEnd ());
pc.WaitForExit( );
i am not able to capture the username and password of the SQL server in
the command prompt..
can anyone please help me?