SQLTeam.com | Weblogs | Forums

Writing to a table, which is in another server(Linked server) using BCP?


#1

Hi,

I am planning to write from a file to a database table, which is in another linked server. I am using the following command.

Exec master..xp_cmdshell
'bcp "[LinkedServer1].DatabaseName.dbo.TableName" in "filename.txt" -S ServerName -T -c'

But I am getting following error.

A valid table name is required for in, out, or format options.

I am certain that this table exists as "SELECT * FROM [LinkedServer1].DatabaseName.dbo.TableName" is working

Can some please help me in correcting syntax issues.

Thanks

Rami Reddy


#2

Use the -S parameter to connect to the other server.

bcp DatabaseName.dbo.TableName in filename.txt -S remoteservernamegoeshere -T -c

Bcp runs from the command prompt, and you tell it which server. It can be any server. Use that feature instead of what you are trying to do.


#3

I guess I don't understand why this is being done across a linked server. Why not have the target server simply do a BULK INSERT (or BCP) directly from the file and avoid the proverbial middle man?