BULK INSERT from a different server

2019-08-19 02:41发布

问题:

I am using T-SQL with SQL Server 2012.

Here is my question: I have a text file on server 10.10.10.1. I want to create a temporary table on server 10.10.10.2 from the previous text file.

According to my research, BULK INSERT works on local C: directory.

Is there a way to do the following?

BULK INSERT dbo.#G2
FROM '10.10.10.1.C:\File\textfile.txt'
WITH
(
  CODEPAGE = '1252',
  FIELDTERMINATOR = ';',
  CHECK_CONSTRAINTS
)

Thank you for your help.

回答1:

You can read data from a file share (\\computer\share\folder\file) but the SQL Server process has to have access. As SQL Server generally runs as a local service account it can only access shares that allow anonymous access (so anyone can read the content of the share).

Better up upload to a folder on the server, but of course that means sharing a writable folder from the database server. While controllable (eg. dedicated partition, controlled ACL) it is still not ideal.