Executing scripts from C# using sqlcmd.exe

  • 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();

    }

  • 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.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply