System_CAPS_ICON_warning.jpg Warning

SQL Server Native Client (SNAC) is not supported beyond SQL Server 2012. Avoid using SNAC in new development work, and plan to modify applications that currently use it. The Microsoft ODBC Driver for SQL Server provides native connectivity from Windows to Microsoft SQL Server and Microsoft Azure SQL Database.

Reads a data file format definition from the specified format file.

RETCODE bcp_readfmt (  
        HDBC hdbc,  
        LPCTSTR szFormatFile);  

Is the bulk copy-enabled ODBC connection handle.

Is the path and file name of the file containing the format values for the data file.


After bcp_readfmt reads the format values, it makes the appropriate calls to bcp_columns and bcp_colfmt. There is no need for you to parse a format file and make these calls.

To persist a format file, call bcp_writefmt. Calls to bcp_readfmt can reference saved formats. For more information, see bcp_init.

Alternately, the bulk-copy utility (bcp) can save user-defined data formats in files that can be referenced by bcp_readfmt. For more information about the bcp utility and the structure of bcp data format files, see Bulk Import and Export of Data (SQL Server).

The BCPDELAYREADFMT value of the eOption parameter of bcp_control modifies the behavior of bcp_readfmt.

System_CAPS_ICON_note.jpg Note

The format file must have been produced by version 4.2 or later of the bcp utility.

// Variables like henv not specified.  
HDBC      hdbc;  
DBINT      nRowsProcessed;  
// Application initiation, get an ODBC environment handle, allocate the  
// hdbc, and so on.  
// Enable bulk copy prior to connecting on allocated hdbc.  
// Connect to the data source, return on error.  
if (!SQL_SUCCEEDED(SQLConnect(hdbc, _T("myDSN"), SQL_NTS,  
   _T("myUser"), SQL_NTS, _T("myPwd"), SQL_NTS)))  
   // Raise error and return.  
// Initialize bulk copy.   
if (bcp_init(hdbc, _T("myTable"), _T("myData.csv"),  
   _T("myErrors"),    DB_IN) == FAIL)  
   // Raise error and return.  
if (bcp_readfmt(hdbc, _T("myFmtFile.fmt")) == FAIL)  
   // Raise error and return.  
if (bcp_exec(hdbc, &nRowsProcessed) == SUCCEED)  
   cout << nRowsProcessed << " rows copied to SQL Server\n";  
// Carry on.  

Bulk Copy Functions

Community Additions