views:

73

answers:

2

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'

UPDATE:

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 solutions?

A: 

The -n option removes the 1> 2> ... line number prompts and afaik there are no other flags that go along with it so remove the -1.

Alex K.
I try this too, osql.exe -E -i"CarpetaUno\TextFile1.sql" and fails same.
alhambraeidos
Then it sounds like a prob with the SQL inside "CarpetaUno\TextFile1.sql"
Alex K.
Can it fails if I use utf-8 encoding in file ??
alhambraeidos
Yes, it wont work with utf-8, use ucs2 (little endn.) or utf16 (or ansi), alternatively try the sqlcmd.exe utility
Alex K.
+2  A: 

I think you're barking up the wrong tree..

Error 102 is incorrect SQL syntax, more than likely from the source SQL file.

Update
I think you've answered your own question.. 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.

The bottom line is: Use SQLCMD.exe

Dog Ears
TextFile1.sql contents, is OK, I test using SSMS. Can it fails if I use utf-8 encoding in file ??
alhambraeidos
Try running it using sqlcmd.exe
Dog Ears