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 7, 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 @ 6:23 AM
Points: 35,772, Visits: 32,445
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #572917
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse