Script runs fine in SQL Management Studio but errors using OSQL

  • Has anyone run into problems where a script that runs with no errors in SQL Management Studio but the exact same script has errors running using OSQL command-line?

    We wrote a utility to run our update scripts using OSQL command line via ShellExecute and have found that sometimes the script has errors that really shouldn't be errors. I can run the same script in SQL Management Studio with no errors at all.

    Any ideas??

  • What kind of errors are you getting?

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • It varied..

    One was where we were adding 3 columns in separate calls and the first column never got added, the second and third did, however, and the resulting SP created later caused the error.

    There was also one line where we were creating a table and about 100 lines further down in the script, it said that the table didn't exists.

    I fixed all the syntax errors. I found that the developer used the syscolumns table .vs sys.columns view and corrected all those and the first column got added then and that error went away. (We are using 2005)

    It is just frustrating to have perfectly good code but have OSQL crap out on ya'.

  • So, why don't you use SQLCMD instead? That is the new command line tool for SQL Server 2005.

    BTW - errors like that would also show up in SSMS if they are run the same way.

    One advantage to using SQLCMD is that you can actually test the script in SSMS in SQLCMD mode to validate the script works correctly.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • We have been contemplating rewriting the utility to use sqlcmd.

  • Jeffrey Williams (10/23/2008)


    One advantage to using SQLCMD is that you can actually test the script in SSMS in SQLCMD mode to validate the script works correctly.

    How?

  • just open the script with SSMS in a query window.

    One of your SSMS tabs is named "Query" there is an item named "SQLCMD mode".

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • I'm going through the same problem, have you ever found a fix for this? I don't understand why something can run on SSMS and not work on OSQL/SQLCMD.

  • - what kind of error are you getting ??

    - can you post the script ?

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

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

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