I use the following command to run the script file on the MS SQL Server.
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -d imdb -U sa -P XXX -i data.sql
And I get the error
Sqlcmd: 'data.sql': Invalid filename.
But I can run it with this
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -d imdb -U sa -P XXX -Q "the content of data.sql"
Does anyone know why I get this error? Thanks a lot.
I had the same problem, but the error was because the sql script wasn't inside the container so, in order to execute the command above, you can copy the sql script to the container with the following command:
docker cp /your/local/path/data.sql sqlserver:/home/
This put the file inside the docker instance in the home
folder. Even you can list the files inside that folder with:
docker exec -it sqlserver ls /home
And after that you can use the command
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -d testdb -U sa -P XXX -i data.sql
In my case, I had to add the following SQL command at the top of data.sql
script:
USE testdb
GO
That because for some reason it wasn't executing the commands inside the testdb
.
So I hope it helps you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.