Running Scripts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carlos Wong

    #1

    Running Scripts

    I have a problem... I need to do a SQL script runner.
    Somenthing like the query analizer, but hidding the code.

    I try with the sqlCommand, but doesn't work. The scripts
    have: "go"es, "commit"s, etc. And I need to present the
    command result.

    Somebody can give a recomendation about this, I try doing
    this:

    private System.Data.Sql Client.SqlConne ction Connection;
    private System.Data.Sql Client.SqlComma nd
    Scriptor;
    System.Windows. Forms.TextBox scriptt;
    Connection = new System.Data.Sql Client.SqlConne ction();
    this.Scriptor = new
    System.Data.Sql Client.SqlComma nd();
    Connection.Conn ectionString = "data
    source=DBSERVER ;initial catalog=TEST;in tegrated
    security=SSPI;p ersist s" +
    "ecurity
    info=False;pack et size=4096";
    scriptt = new System.Windows. Forms.TextBox() ;
    Scriptor.Connec tion = this.Connection ;

    byte[] buffer;
    System.IO.FileS tream fscript =
    new System.IO.FileS tream
    (textBox1.Text, System.IO.FileM ode.Open);
    System.Text.ASC IIEncoding trans =
    new System.Text.ASC IIEncoding();
    int n;
    buffer = new byte[bufferSize];
    Scriptor.Comman dText="";
    scriptt.Clear() ;
    string temp;
    n = fscript.Read
    (buffer,0,buffe rSize);
    while (n != 0)
    {
    temp = trans.GetString
    (buffer)
    Scriptor.Comman dText =
    Scriptor.Comman dText+temp;
    buffer = new byte
    [bufferSize];
    n = fscript.Read
    (buffer,0,buffe rSize);
    }
    fscript.Close() ;

    Connection.Open ();
    Scriptor.Prepar e();
    scriptt.Text =
    Scriptor.Comman dText;
    scriptt.AppendT ext("Esto
    salió "+Scriptor.Exec uteNonQuery());
    Connection.Clos e();
Working...