Search code examples
sql-server-2008bcp

How can I Import and export data using bcp command?


I am Trying to import and export data using bcp tool but it was giving errors which are:-

  SQLState = 08001, NativeError = -1
Error = [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces:
 Error Locating Server/Instance Specified [xFFFFFFFF].
SQLState = 08001, NativeError = -1
Error = [Microsoft][SQL Server Native Client 10.0]A network-related or instance-
specific error has occurred while establishing a connection to SQL Server. Serve
r is not found or not accessible. Check if instance name is correct and if SQL S
erver is configured to allow remote connections. For more information see SQL Se
rver Books Online.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Login timeout expired

I am currently using SQL server 2008 r2 version.

Command Which are I am using:-

C:\Program Files\Microsoft SQL Server\100\Tools\Binn>bcp Alldbtypes.dbo.Misc_dty
    pes out C:\Workarea\Data\EmployeeData.dat -S 192.168.1.117\SqlSrv2008 -T

Please suggest me how can I use bcp command.


Solution

  • In order to user the bpc, it is important to know the schema of your database.

    I believe the Export will look something like this:

    bcp "Select Column1, Column2 FROM Database.Schema.Table" queryout
    C:\bcp_outputQuery.txt -SYourServerName -T -c
    

    OR something like this:

    bcp DatabaseName.Schema.TableName out C:\Data\tableout.txt -c –T
    

    For the import it would look something like this:

    bcp Database.Schema.Table in
    C:\bcp_outputQuery.txt -SYourServername -T -c