473,657 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OSQL userName and Password Prompt.

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?

Sep 21 '06 #1
11 3624
What actually happens when this code runs?

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?

Sep 21 '06 #2

"gopal" <go*********@gm ail.comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.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
|
| 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?
|

You need to pass them as command arguments (run osql /? for details).
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.
Sep 21 '06 #3
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?

Sep 21 '06 #4
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?
Sep 21 '06 #5

"gopal" <go*********@gm ail.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.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.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");

You need to block the main thread, else your main thread will exit pulling
down stdin stderr and stdout

proc.StandardIn put.WriteLine (@"go");
Console.ReadLin e();
}
Sep 21 '06 #6
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" <go*********@gm ail.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.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.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");

You need to block the main thread, else your main thread will exit pulling
down stdin stderr and stdout

proc.StandardIn put.WriteLine (@"go");
Console.ReadLin e();
}
Sep 21 '06 #7
Any response??
gopal wrote:
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" <go*********@gm ail.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.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.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");

You need to block the main thread, else your main thread will exit pulling
down stdin stderr and stdout

proc.StandardIn put.WriteLine (@"go");
Console.ReadLin e();
}
Sep 21 '06 #8

"gopal" <go*********@gm ail.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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.ReadLin e() 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.
Sep 21 '06 #9
Willy, I am sorry for this..what i had mailed for..Here is the code i
have
static void Main(string[] args)
{
String[] sConnectionStri ng;
try
{

ProcessStartInf o psi = new ProcessStartInf o("osql.exe", "-Usa -Psa");
psi.RedirectSta ndardOutput=fal se;
psi.RedirectSta ndardInput=fals e;
psi.RedirectSta ndardError=fals e;
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 (@"go");
Console.ReadLin e();
proc.StandardIn put.WriteLine ("Hello");
proc.StandardIn put.WriteLine ("there");

}
catch (Exception e)
{
Console.WriteLi ne("{0}",e.ToSt ring());
}
}
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);
}
}

}

It gives me error "Standard out has not been redirected"

Willy Denoyette [MVP] wrote:
"gopal" <go*********@gm ail.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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.ReadLin e() 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.
Sep 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7085
by: red | last post by:
I know this is probably a faq but it is hard to search for this exact problem. When I put this on a php page: <? $link = mysql_connect("localhost", "cardini", "password") or die("Could not connect : " . mysql_error()); echo "Connected successfully\n"; mysql_select_db("articles") or die("Could not select database");
3
6130
by: arfanameer | last post by:
How can I create a new database on sql server using OSQL command in command prompt. I have the sql file for database creation and I use the following command C:\> osql -S servername -U sa -i db1.sql it prompt my for password n i enter it since sa has a blank password but after that it returns the following error. 1> 2> 3> Msg 170, Level 15, State 1, Server servername, Procedure , Line 2
24
4734
by: LineVoltageHalogen | last post by:
Greetings All, I was hoping that someone out there has run into this issue before and can shed some light on it for me. I have a stored procedure that essentially does a mini ETL from a source OLTP DB to a the target Operational Data Store. This is still in development so both DB's reside on the same machine for convenience. The stored proc runs successfully from within Query analyzer and this holds true on the following platforms: XP...
1
2375
by: Florimond | last post by:
Can I use osql to known the database install on a server via 'guest' account ? I had over 300 servers with sql server all around France (different version : 6.5, 7 and 8) I need to check all database on each servers from my place. Of course, also it would have been to easy, I don't have all 'sa' password... Is that possible to use the 'guest' account to execute a query like
5
5836
by: mike | last post by:
I have a question. I am doing some work for someone and I have a batch file that they can run that will execute an OSQL line and a DTSRUN line. In both lines I run them using the /S /U /P switches and of course the /N or /i switch to tell it what to run. I have also tried replacing the /U /P switches with the /E switch. My problem is that as long as I specify the users password on the OSQL line (either with /U & /P or with /E & /P) it...
7
2276
by: gopal | last post by:
Hi, I have a console application whose purpose 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 .
11
13960
by: Kevin O'Brien | last post by:
Hello, I am creating a sign on screen for my application in which I want to store the username and password in a database table. I was thinking of putting a combo box connected to the database to pull up the usernames and then having a textbox for the user to enter their password. Can someone tell me please how to compare the contents of the textbox to the password in the database?
5
3771
by: libra786 | last post by:
I have created a blog and have added a login box which prompts the user for login and id before posting- The username and password have been stored in the database, however when i enter the username and pasword it does not seem to compare the values entered with anything. It jus keeps giving the prompt box to enter details. But if i click cancel, then it tels me the incorrect credentials ave been entered i have tried many ways to solve this...
0
1728
by: =?Utf-8?B?TW9uaXF1ZQ==?= | last post by:
I just reinstalled IIS as I worked with wamp before and yet I didn't find out how to have a php and a asp server working the same time on a computer. (I had to uninstall the IIS to get wamp at work). But my question now is only about asp. Everything works in asp only that there comes a popup that ask for username and password. I searched what could be meant and saw you use the terminology "IUSR_COMUTERNAME and IWAM_COMPUTERNAME". I...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.