Using DMO to run sql scripts.

  • I am trying to create a vb exe that lets our users pick a script that they want to run, that updates one or more stored procedures and permissions.

    I read Andy's article on his scriptrunner, and have gotten close to a finished product. My hang up is with the "go". I am using executewithresultsandmessages.

    Am i barking up the wrong tree, or do I have to parse the file for the go's and run each segement of code individually.

    Thanks for any help

    Tom Goltl

  • I thought the "go's" would work, haven't looked lately. Can you post a chunk of the code?

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • I copied your code for the section I am having problems with. Here is the line that won't run the entire script:

    oDB.ExecuteWithResultsAndMessages sScript, , sMsg.

    I get an error with the "go" in the script when I run with that command.

    I changed the command to this: oDB.ExecuteImmediate sScript, SQLDMOExec_ContinueOnError

    It will now run but I can't get any of the error messages from this command.

    Thanks for looking.

    Tom Goltl

  • Man, I'll have to stop posting code that has bugs in it! Put in a debug.print to confirm that the CommandTerminator property is "GO".

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • The commandterminator property is set to "go". But it certainly doesn't like the go's in the script.

    Just so you don't get down, Your sample code is a big help to us hacks.

    Tom

  • I'll try to research a little more. Only thought that I have right now is maybe the terminator is case sensitive?

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • I succesfully changed the commandterminator, but that made know difference. The error message: incorrect syntax near "go".

    I'll keep on trying.

    Thanks

    Tom

  • Use db.ExecuteImmediate (strTSQLCMD)

    then test err.number, this works just fine.

    We are using it to rebuild a database object by object from SQL scripts in source control - these scripts have GO statements in them.

    Hope this helps. Al

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

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