Search code examples
sql-servercommand-line-interfacebcpbulk-load

How to write using BCP to a remote SQL Server?


I have a remote SQL Server with a hostname I am using to connect to.

BCP suggests to use

bcp DBName.dbo.tablename in C:\test\yourfile.txt -c -T -t

However when I try this it does not connect to DBName as that is not a valid alias. I get native error 2.

How to I run BCP but specify an internet / network address to connect to, not an MSSQL server name?


Solution

  • How to I run BCP but specify an internet / network address to connect to, not an MSSQL server name?

    You can specify the IP address (here just 127.0.0.1) instead of the server name.

    bcp DBName.dbo.tablename in "C:\test\yourfile.txt" -c -T -t -S"127.0.0.1\instance"

    If you truly want to go IP\port only then use IP address and port separated by comma

    bcp DBName.dbo.tablename in "C:\test\yourfile.txt" -c -T -t -S"127.0.0.1,60905"

    Of course in that case you would need to know the port the instance is using, and your instance should be set to use a fixed port