I have a txt file on my local PC. I run localy Java app which connects to remote MSSQL. Now I need to bulk insert from that text file into my database table.

However, SQL login can't read my file. I get:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot bulk load because the file "D:/My_Files/my_file.txt" could not be opened. Operating system error code 21(The device is not ready.)

I set permissions on My_Files folder for 'Everyone'. I can't create a Windows user with the same name like SQL login because it is too long for Windows user. Is there a solution?

  • A remote SQL Server has no way of reading a file on your local PC. Try bcp.
    – mustaccio
    May 24, 2022 at 22:54
  • Why not have the Java app bulk insert into your database after reading from the file itself?
    – J.D.
    May 24, 2022 at 22:59
  • I am calling a store procedure from Java. This store procedure uses bulk insert from my local txt file to a table in remote db.
    – Hrvoje T
    May 24, 2022 at 23:00
  • J.D. that could work too, but I wrote the code like this, to bulk insert from a store procedure and it worked fine localy. Now I deployed my code and have trouble with remote db user accessing my text file.
    – Hrvoje T
    May 24, 2022 at 23:02

1 Answer 1


As mustaccio pointed out, a local path is not going to be accessible from the SQL Server, which is the error you're receiving regarding "D:/My_Files/my_file.txt. It's looking for a file on the D: drive on the server that your SQL instance is installed on (not your local computer's D: drive).

You may be able to create a network share to that folder and reference it by UNC path in the SQL Server instance though. How to do that is more so in the scope of a ServerFault question.

Alternatively you can add code in your Java program to read the local file and then do a BULK INSERT command from the app to your database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.