sql-serverlinuxubuntu-16.04

How make sqlcmd hold file access rights on linux?


Just installed sql-server on Ubuntu 16.04, 2 days ago. Using sqlcmd for bulk insert i got:

Msg 4860, Level 16, State 1, Line 6 Cannot bulk load. The file "~/test_data.txt" does not exist or you don't have file access rights.

Yes the file did exist, i made sure of it using the command cat.

Then i tried bcp tool, but i got:

SQLState = S1000, NativeError = 0 Error = [Microsoft][ODBC Driver 13 for SQL Server]Unable to open BCP host data-file

Also tried installing visual studio code and adding mssql extension but i got the same "file access rights" warning. And already used the chmod 777 trying to fix it. Didn't work.

Command bulk insert sqlcmd:

    BULK INSERT TestEmployees FROM '~/test_data.txt'
WITH(
    rowterminator = ','
);

Command on bcp tool

bcp auth in path/auth2.tsv -S localhost -U sa -P <my password> -d Trabalho1BD -c

Solution

  • I think your problem is the '~/test_data.txt' part of your bulk insert command. Specifically, that says "find a file called test_data.txt in the home directory". But whose home directory? Not yours! It's looking for the file in the home directory of the account that's running your SQL Server. Try changing that to a full path (i.e. '/home/«username»/test_data.txt' and that should do it.