|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
OSQL userName and Password Prompt.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 ProcessStartInfo psi = new ProcessStartInfo("osql",""); psi.RedirectStandardInput = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = false; psi.CreateNoWindow = false; psi.UseShellExecute = false; Process pc = Process.Start(psi); Console.WriteLine(pc.StandardOutput.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?
Show quote
Hide quote
"gopal" <gopal.sr***@gmail.com> wrote in message You need to pass them as command arguments (run osql /? for details).news:1158834312.459600.30730@b28g2000cwb.googlegroups.com... | 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 | | ProcessStartInfo psi = new ProcessStartInfo("osql",""); | psi.RedirectStandardInput = false; | psi.RedirectStandardOutput = true; | psi.RedirectStandardError = false; | psi.CreateNoWindow = false; | psi.UseShellExecute = false; | Process pc = Process.Start(psi); | Console.WriteLine(pc.StandardOutput.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? | I also do not see what you are trying to achieve here, osql is an interactive utility, you will have to write commands to stdin and read responses from stdout, that is redirect stdin and stdout. Why not simply run osql from the command line? Willy. What actually happens when this code runs?
Ciaran O'Donnell Show quoteHide quote "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 > > ProcessStartInfo psi = new ProcessStartInfo("osql",""); > psi.RedirectStandardInput = false; > psi.RedirectStandardOutput = true; > psi.RedirectStandardError = false; > psi.CreateNoWindow = false; > psi.UseShellExecute = false; > Process pc = Process.Start(psi); > Console.WriteLine(pc.StandardOutput.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? > > 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 Show quoteHide quote "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 > > ProcessStartInfo psi = new ProcessStartInfo("osql",""); > psi.RedirectStandardInput = false; > psi.RedirectStandardOutput = true; > psi.RedirectStandardError = false; > psi.CreateNoWindow = false; > psi.UseShellExecute = false; > Process pc = Process.Start(psi); > Console.WriteLine(pc.StandardOutput.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? > > 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.Diagnostics; using System.IO; using Microsoft.Win32; using System.Threading; namespace ConsoleApplication3 { /// <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 { ProcessStartInfo psi = new ProcessStartInfo("osql.exe","-Usa -Psa"); psi.RedirectStandardOutput=true; psi.RedirectStandardInput=true; psi.RedirectStandardError=true; psi.UseShellExecute=false; psi.CreateNoWindow=true; Process proc = Process.Start (psi); ProcessOutputReader por = new ProcessOutputReader (proc); por.Start(); proc.StandardInput.WriteLine (@"sp_help GO"); proc.StandardInput.WriteLine(); proc.StandardInput.WriteLine ("mohan"); proc.StandardInput.WriteLine ("rahul"); class ProcessOutputReader { Process proc; public ProcessOutputReader (Process proc) { this.proc = proc; } public void Start() { new Thread (new ThreadStart(ReadAll)).Start(); } void ReadAll() { StreamReader reader = proc.StandardOutput; string line; while ((line = reader.ReadLine())!=null) Console.WriteLine ("Process output: {0}", line); } } } } Ciaran O''Donnell wrote: Show quoteHide quote > 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 > > > > ProcessStartInfo psi = new ProcessStartInfo("osql",""); > > psi.RedirectStandardInput = false; > > psi.RedirectStandardOutput = true; > > psi.RedirectStandardError = false; > > psi.CreateNoWindow = false; > > psi.UseShellExecute = false; > > Process pc = Process.Start(psi); > > Console.WriteLine(pc.StandardOutput.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? > > > >
Show quote
Hide quote
"gopal" <gopal.sr***@gmail.com> wrote in message You need to block the main thread, else your main thread will exit pulling news:1158836389.836924.251110@i42g2000cwa.googlegroups.com... |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.Diagnostics; | using System.IO; | using Microsoft.Win32; | using System.Threading; | | namespace ConsoleApplication3 | { | /// <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 | { | | ProcessStartInfo psi = new ProcessStartInfo("osql.exe","-Usa -Psa"); | psi.RedirectStandardOutput=true; | psi.RedirectStandardInput=true; | psi.RedirectStandardError=true; | psi.UseShellExecute=false; | psi.CreateNoWindow=true; | Process proc = Process.Start (psi); | ProcessOutputReader por = new ProcessOutputReader (proc); | por.Start(); | proc.StandardInput.WriteLine (@"sp_help GO"); | proc.StandardInput.WriteLine(); | | proc.StandardInput.WriteLine ("mohan"); | proc.StandardInput.WriteLine ("rahul"); down stdin stderr and stdout proc.StandardInput.WriteLine (@"go"); Console.ReadLine(); } Hi,
i tried putting the two lines, but i am getting the following error Standard Out has not been redirected. Atleast i would like the prompt to be displayed when the application is started..for inutting Databaser UserName and Password.. Willy Denoyette [MVP] wrote: Show quoteHide quote > "gopal" <gopal.sr***@gmail.com> wrote in message > news:1158836389.836924.251110@i42g2000cwa.googlegroups.com... > |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.Diagnostics; > | using System.IO; > | using Microsoft.Win32; > | using System.Threading; > | > | namespace ConsoleApplication3 > | { > | /// <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 > | { > | > | ProcessStartInfo psi = new ProcessStartInfo("osql.exe","-Usa -Psa"); > | psi.RedirectStandardOutput=true; > | psi.RedirectStandardInput=true; > | psi.RedirectStandardError=true; > | psi.UseShellExecute=false; > | psi.CreateNoWindow=true; > | Process proc = Process.Start (psi); > | ProcessOutputReader por = new ProcessOutputReader (proc); > | por.Start(); > | proc.StandardInput.WriteLine (@"sp_help GO"); > | proc.StandardInput.WriteLine(); > | > | proc.StandardInput.WriteLine ("mohan"); > | proc.StandardInput.WriteLine ("rahul"); > > You need to block the main thread, else your main thread will exit pulling > down stdin stderr and stdout > > proc.StandardInput.WriteLine (@"go"); > Console.ReadLine(); > } Any response??
gopal wrote: Show quoteHide quote > Hi, > > i tried putting the two lines, but i am getting the following error > > Standard Out has not been redirected. > > Atleast i would like the prompt to be displayed when the application is > started..for inutting Databaser UserName and Password.. > > > Willy Denoyette [MVP] wrote: > > "gopal" <gopal.sr***@gmail.com> wrote in message > > news:1158836389.836924.251110@i42g2000cwa.googlegroups.com... > > |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.Diagnostics; > > | using System.IO; > > | using Microsoft.Win32; > > | using System.Threading; > > | > > | namespace ConsoleApplication3 > > | { > > | /// <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 > > | { > > | > > | ProcessStartInfo psi = new ProcessStartInfo("osql.exe","-Usa -Psa"); > > | psi.RedirectStandardOutput=true; > > | psi.RedirectStandardInput=true; > > | psi.RedirectStandardError=true; > > | psi.UseShellExecute=false; > > | psi.CreateNoWindow=true; > > | Process proc = Process.Start (psi); > > | ProcessOutputReader por = new ProcessOutputReader (proc); > > | por.Start(); > > | proc.StandardInput.WriteLine (@"sp_help GO"); > > | proc.StandardInput.WriteLine(); > > | > > | proc.StandardInput.WriteLine ("mohan"); > > | proc.StandardInput.WriteLine ("rahul"); > > > > You need to block the main thread, else your main thread will exit pulling > > down stdin stderr and stdout > > > > proc.StandardInput.WriteLine (@"go"); > > Console.ReadLine(); > > } "gopal" <gopal.sr***@gmail.com> wrote in message Do you think this is a helpdesk or something?news:1158846093.539727.326660@e3g2000cwe.googlegroups.com... | Any response?? I did not ask to add two lines, I asked to add a Console.ReadLine() to prevent the main thread to exit before the sub-thread was even able to do anything usefull. If you need to get user and password, you can get them from the command line and insert both in the string you pass as arguments to osql. Willy. Willy, I am sorry for this..what i had mailed for..Here is the code i
have static void Main(string[] args) { String[] sConnectionString; try { ProcessStartInfo psi = new ProcessStartInfo("osql.exe","-Usa -Psa"); psi.RedirectStandardOutput=false; psi.RedirectStandardInput=false; psi.RedirectStandardError=false; psi.UseShellExecute=false; psi.CreateNoWindow=true; Process proc = Process.Start (psi); ProcessOutputReader por = new ProcessOutputReader (proc); por.Start(); proc.StandardInput.WriteLine (@"go"); Console.ReadLine(); proc.StandardInput.WriteLine ("Hello"); proc.StandardInput.WriteLine ("there"); } catch (Exception e) { Console.WriteLine("{0}",e.ToString()); } } class ProcessOutputReader { Process proc; public ProcessOutputReader (Process proc) { this.proc = proc; } public void Start() { new Thread (new ThreadStart(ReadAll)).Start(); } void ReadAll() { StreamReader reader = proc.StandardOutput; string line; while ((line = reader.ReadLine())!=null) Console.WriteLine ("Process output: {0}", line); } } } It gives me error "Standard out has not been redirected" Willy Denoyette [MVP] wrote: Show quoteHide quote > "gopal" <gopal.sr***@gmail.com> wrote in message > news:1158846093.539727.326660@e3g2000cwe.googlegroups.com... > | Any response?? > > Do you think this is a helpdesk or something? > > I did not ask to add two lines, I asked to add a Console.ReadLine() to > prevent the main thread to exit before the sub-thread was even able to do > anything usefull. > If you need to get user and password, you can get them from the command line > and insert both in the string you pass as arguments to osql. > > Willy. "gopal" <gopal.sr***@gmail.com> wrote in message You need this:news:1158852476.230622.99560@m7g2000cwm.googlegroups.com... | Willy, I am sorry for this..what i had mailed for..Here is the code i | have | psi.RedirectStandardOutput=true; before starting osql. And what's the purpose of this? proc.StandardInput.WriteLine ("Hello"); what do you think osql will do with it? Honestly I don't quite understand what you are trying to achieve. osql is a end-user tool (a DBA utility) why are you wrapping this in yet another console application, IMO it add's no value. Willy. Hi
The purpose of this console application is to run the OSQL utility from my console application. When my application is run, the OSQL utility is started and it has to prompt for Database UserName & Password [Database Name & SQL files will be provided as other options for this OSQL]. But i am having problems in getting from the prompt, Database - UserName & Password Once I get userName & Password, i already have the Database Server Name & SQL file Now i will install the SQL files on the particular database Willy Denoyette [MVP] wrote: Show quoteHide quote > "gopal" <gopal.sr***@gmail.com> wrote in message > news:1158852476.230622.99560@m7g2000cwm.googlegroups.com... > | Willy, I am sorry for this..what i had mailed for..Here is the code i > | have > | > You need this: > psi.RedirectStandardOutput=true; > before starting osql. > > And what's the purpose of this? > proc.StandardInput.WriteLine ("Hello"); > what do you think osql will do with it? > Honestly I don't quite understand what you are trying to achieve. osql is a > end-user tool (a DBA utility) why are you wrapping this in yet another > console application, IMO it add's no value. > > Willy.
Learning with command-line vs IDE
How to determine if I am in a web or a windows application TypeConverter.GetStandardValues Naming Conventions /// <example> See TODO even if file is not open in editor Passing Arguments ByRef/ByVal C# Events & Event Handlers Copy nodes of one treeview to another Clipboard question! |
|||||||||||||||||||||||