none
Error using osql.exe

    Question

  • Hi all,

    I use sql server 2005 enterprise, windows server 2003.

    I try execute osql.exe command, for execute sql file in my server DESSQL:

        osql.exe -E -n-1 -i"CarpetaUno\TextFile1.sql"


    I get this error:

        Msg 102, Level 15, State 1, Server DESSQL, Line 1
        Incorrect syntax near 'n'

    TextFile1.sql contents:

    CREATE DATABASE PRUEBA;

     

     

    I try this too,

     

        osql.exe -E -i"CarpetaUno\TextFile1.sql"

     

        1> 2> Msg 102, Level 15, State 1, Server DESSQL, Line 1

        Incorrect syntax near 'n'

     

     

    Finally, I use SQLCMD command:

     

    SQLCMD -E -b -i"CarpetaUno\TextFile1.sql"

     

    But not works using osql command !!

     

    I test:

     

     

    1.) using -S ServerName option,

     

    2.) using absolute path: osql.exe -E --i C:\CarpetaUno\TextFile1.sql

     

    3.) TextFile1.sql contents, is OK, I test using SSMS

     

        CREATE DATABASE PRUEBA;

     

        DROP DATABASE PRUEBA;

     

     

    but I get the same error, in all tests.

     

    Can it fails if I use utf-8 encoding in file ???


    Any suggestions, please? Thanks


    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Tuesday, July 27, 2010 10:49 AM

Answers

All replies

  • Going off the fact that you got the same error on the second attempt; despite the fact you did not set the -n flag, I would suggest that there may be something wrong with your SQL file...
    Tony C
    Tuesday, July 27, 2010 11:08 AM
  • Hello,

    Try to run the sql script in SSMS, do you get the same error?


    Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de
    Tuesday, July 27, 2010 11:10 AM
  • Check out the BOL link: http://msdn.microsoft.com/en-us/library/aa214012(SQL.80).aspx

    -i will only open in the current folder, try typing the full name:

    osql.exe -E --i C:\CarpetaUno\TextFile1.sql

    If the CarpetaUno folder is on the C:\ drive.

    Did not understod why you added -n-1 (to remove numbering in the sql file?)

    Tuesday, July 27, 2010 11:11 AM
  • You have not mentioned the server name using -S switch and also try using the absolute path of the input file.

    Hope this helps !


    Pradeep Adiga http://www.sqldbadiaries.com
    Tuesday, July 27, 2010 11:17 AM
  • Finally, I use SQLCMD command:

     

    SQLCMD -E -b -i"CarpetaUno\TextFile1.sql"

     

    But not works using osql !!!

     

    I test:

     

    1.) using -S ServerName option,

    2.) using absolute path: osql.exe -E --i C:\CarpetaUno\TextFile1.sql

     

     

    3.) TextFile1.sql contents, is OK, I test using SSMS

    CREATE DATABASE PRUEBA;

    DROP DATABASE PRUEBA;

     

    but I get the same error, in all tests.

    Can it fails if I use utf-8 encoding in file ???

     

    UPDATE:

     

     OSQL accepts ANSI and Unicode encoded files, BUT I tried opening my file with notepad++ changed the encoding to UTF-8 and I got similar errors.

    A quick google gave me this and this with a little bit more information.

     


    Should "Hi", "Thanks" and taglines and salutations be removed from posts? http://meta.stackoverflow.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts
    Wednesday, July 28, 2010 12:46 PM
  • OSQL is deprecated anyway and replace by SQLCMD, so it is either way the better choice for you.

    -Jens


    Jens K. Suessmeyer http://blogs.msdn.com/Jenss
    Wednesday, July 28, 2010 1:10 PM