0

I have a .sql file in my linux machine. I would like to connect to MS SQL database in the remote windows machine and run the .sql file in that database.

osql -S servername -U xx -P yy runs okay and returns a SQL window like:

SQL>

I can run individual queries using this. I have a .sql file with lot of sql commands which I need to run on a database called abc. How can I do that using shell command. The following doesn't work for me,

osql -S mssql -U xx -P yy -i /home/admin/Script.sql -D abc

I get the following error,

Illegal option -i
Syntax: osql -S server -U user -P password

The path of Script.sql file is correct as this opens the file - vi /home/admin/Script.sql. Not sure what the problem is. Any help would be appreciated

  • 1
    What error message do you get? We can't see your screen so please edit the question to include the error message - as text. Also, `osql` checks your ODBC configuration before invoking `isql`... have you tried invoking `isql` directly? – AlwaysLearning May 13 '20 at 09:34
  • What distribution of Linux? Both [`sqlcmd`](https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-ver15) and [`mssql-cli`](https://learn.microsoft.com/en-us/sql/tools/mssql-cli?view=sql-server-ver15) are available on Linux and both accept sql files as input parameters. [`osql`](https://learn.microsoft.com/en-us/sql/tools/osql-utility?view=sql-server-ver15), on the other hand, has been deprecated for some time and its use should be avoided (as the documentation tells you). – Thom A May 13 '20 at 09:55
  • @AlwaysLearning I have added the error message in the question. any thoughts? – Aparna Moorthi May 13 '20 at 12:44
  • @Larnu thanks for the comment. I am going to try a little bit more. If osql doesn't work, I am going to try sqlcmd for which I have to start with the installations – Aparna Moorthi May 13 '20 at 12:46

1 Answers1

0

osql isn't working for me. I tried sqlcmd and it worked like a charm. Referred these links for ms sql tools installation - http://www.thesqlreport.com/?p=1494, https://sqlserveronlinuxbackup.com/sqlcmd-command-not-found-ubuntu/.

sqlcmd syntax: sqlcmd -S 10.0.0.0 -U xx -P yy -d mydb -i /home/admin/abc.sql