Results 1 to 6 of 6

Thread: Simple way to create databases from SQL script?

  1. #1
    Join Date
    Dec 2006
    Location
    Minneapolis
    Posts
    3

    Simple way to create databases from SQL script?

    I'm looking for the cleanest, most error free way to create databases from scripts generated by SQL 2005. I'm using vb.net 2.0

    I tried taking the script and doing an .ExecuteNonQuery it didn't work. Once I removed the "GO" statements it worked like a charm.

    Ideally, I'd like to execute the scripts (from VB) just as SQL generates them.

    What class/method does one use in .net to execute the scripts as SQL generates them?

    Thanks!

  2. #2
    Join Date
    Aug 2006
    Posts
    57
    If you use the ServerConnection class, you can execute scripts with GOs in them, using the ExecuteNonQuery() method.

    see:

    http://msdn2.microsoft.com/en-us/lib...n_members.aspx

  3. #3
    Join Date
    Dec 2006
    Location
    Minneapolis
    Posts
    3

    Thanks for that info

    I got the SMO to work. One more thing....

    When SQL generates the scripts for the tables, it includes a:

    [USE AX30] <---- my 'working' database name. Which may not be the db name that the user will want (some users will have several db's with the same structure).

    Do you know if there's any way to suppress the 'USE'?

    Thanks!

  4. #4
    Join Date
    Aug 2006
    Posts
    57
    what SMO class are you calling Script() on that includes the USE statement? Table.Script()? it shouldn't include the USE as far as I know...

  5. #5
    Join Date
    Dec 2006
    Location
    Minneapolis
    Posts
    3

    I generated the scripts from the management console.

    I'll look into generating the scrpits right from smo.

    Thanks again for your help.

  6. #6
    Join Date
    Aug 2006
    Posts
    57
    if you want, you can try out a free tool I wrote just for this purpose:

    http://www.elsasoft.org/tools.htm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •