Windows Vista Forums

ADO.Net / Multiple SQL Statements in One Command
  1. #1


    Craig Guest

    ADO.Net / Multiple SQL Statements in One Command

    I'm writing an application to assist in the deployment of some complex
    database schema out of a working DDL script that has already been generated.

    We're targeting SQL 2000 and 2005, and the script runs fine now inside Query
    Analyzer / Management Studio. It's *long* though, and creates thousands of
    objects (stored procs, tables, views) and hundreds of rows of pre-populated
    data (just lots of inserts after the tables are created).

    Is there a way I can run this giant script using System.Data.SqlClient? I
    attempted a simple example and SqlConnection and SqlCommand choke on anything
    with "GO" in it since it's not actually T-SQL.



    Am I really going to have to try to intelligently divide this file up by
    "GO" statements into individual SQL commands and run them individually or is
    there some other way to execute batch statements?

      My System SpecsSystem Spec

  2. #2


    Todd Beaulieu Guest

    RE: ADO.Net / Multiple SQL Statements in One Command

    As you've discovered, GO is not valid in ado.net. so, you'll either have to
    break it up or run it through osql, or whatever it's called these days. Write
    it to a file and shell out to the tool. It seems cheesy, but it's actually a
    decent approach.

    "Craig" wrote:

    > I'm writing an application to assist in the deployment of some complex
    > database schema out of a working DDL script that has already been generated.
    >
    > We're targeting SQL 2000 and 2005, and the script runs fine now inside Query
    > Analyzer / Management Studio. It's *long* though, and creates thousands of
    > objects (stored procs, tables, views) and hundreds of rows of pre-populated
    > data (just lots of inserts after the tables are created).
    >
    > Is there a way I can run this giant script using System.Data.SqlClient? I
    > attempted a simple example and SqlConnection and SqlCommand choke on anything
    > with "GO" in it since it's not actually T-SQL.
    >
    > Am I really going to have to try to intelligently divide this file up by
    > "GO" statements into individual SQL commands and run them individually or is
    > there some other way to execute batch statements?

      My System SpecsSystem Spec

ADO.Net / Multiple SQL Statements in One Command problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
From a command line open several websites in multiple tabs Highlander VB Script 10 25 Aug 2009
Dynamic statements? gurbao PowerShell 2 16 Jun 2009
Using select statements Andrew Falanga VB Script 2 23 Oct 2008
Why doesn't 'using' command allow multiple objects? Israel .NET General 3 26 Jun 2008
Are These Statements True? Barry Vista installation & setup 1 29 Jan 2007