Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Executing scripts from C# using sqlcmd.exe Expand / Collapse
Author
Message
Posted Friday, September 19, 2008 12:10 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 07, 2009 1:42 AM
Points: 20, Visits: 64
How to use sqlcmd utility with blank password. sa user having blank password. Following code gives error :=> Sqlcmd: '-P': Missing argument. Enter '-?' for help. I tried with console application in .net 2008

static void Main(string[] args)
{
string fileName = @"C:\Createtable.sql";

ProcessStartInfo info = new ProcessStartInfo("sqlcmd", @" -S DEV023\SQL2K -U sa -d pubs -o C:\sqlout.txt -i """ + @fileName + @""" -P");

info.UseShellExecute = false;

info.CreateNoWindow = true;

info.WindowStyle = ProcessWindowStyle.Hidden;

info.RedirectStandardOutput = true;

Process p = new Process();

p.StartInfo = info;

p.Start();
}
Post #572280
Posted Friday, September 19, 2008 8:58 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 9:01 PM
Points: 33,111, Visits: 27,037
sumit kende (9/19/2008)
How to use sqlcmd utility with blank password. sa user having blank password. Following code gives error :=> Sqlcmd: '-P': Missing argument. Enter '-?' for help. I tried with console application in .net 2008

static void Main(string[] args)
{
string fileName = @"C:\Createtable.sql";

ProcessStartInfo info = new ProcessStartInfo("sqlcmd", @" -S DEV023\SQL2K -U sa -d pubs -o C:\sqlout.txt -i """ + @fileName + @""" -P");

info.UseShellExecute = false;

info.CreateNoWindow = true;

info.WindowStyle = ProcessWindowStyle.Hidden;

info.RedirectStandardOutput = true;

Process p = new Process();

p.StartInfo = info;

p.Start();
}


Only way to do it is with a "trusted connection". I don't have the precise syntax, but I'll just bet it's in Books Online.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #572917
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse