--- title: "bcp_readfmt | Microsoft Docs" ms.custom: "" ms.date: "03/06/2017" ms.prod: sql ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" ms.reviewer: "" ms.technology: native-client ms.topic: "reference" apiname: - "bcp_readfmt" apilocation: - "sqlncli11.dll" apitype: "DLLExport" helpviewer_keywords: - "bcp_readfmt function" ms.assetid: 654001c8-ae9f-425c-b820-f0191bf89367 author: markingmyname ms.author: maghan monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current" --- # bcp_readfmt [!INCLUDE[appliesto-ss-asdb-asdw-pdw-md](../../includes/appliesto-ss-asdb-asdw-pdw-md.md)] Reads a data file format definition from the specified format file. ## Syntax ``` RETCODE bcp_readfmt ( HDBC hdbc, LPCTSTR szFormatFile); ``` ## Arguments *hdbc* Is the bulk copy-enabled ODBC connection handle. *szFormatFile* Is the path and file name of the file containing the format values for the data file. ## Returns SUCCEED or FAIL. ## Remarks After **bcp_readfmt** reads the format values, it makes the appropriate calls to [bcp_columns](../../relational-databases/native-client-odbc-extensions-bulk-copy-functions/bcp-columns.md) and [bcp_colfmt](../../relational-databases/native-client-odbc-extensions-bulk-copy-functions/bcp-colfmt.md). There is no need for you to parse a format file and make these calls. To persist a format file, call [bcp_writefmt](../../relational-databases/native-client-odbc-extensions-bulk-copy-functions/bcp-writefmt.md). Calls to **bcp_readfmt** can reference saved formats. For more information, see [bcp_init](../../relational-databases/native-client-odbc-extensions-bulk-copy-functions/bcp-init.md). 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)](../../relational-databases/import-export/bulk-import-and-export-of-data-sql-server.md). The **BCPDELAYREADFMT** value of the *eOption* parameter of [bcp_control](../../relational-databases/native-client-odbc-extensions-bulk-copy-functions/bcp-control.md) modifies the behavior of bcp_readfmt. > [!NOTE] > The format file must have been produced by version 4.2 or later of the **bcp** utility. ## Example ``` // 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. SQLSetConnectAttr(hdbc, SQL_COPT_SS_BCP, (SQLPOINTER) SQL_BCP_ON, SQL_IS_INTEGER); // 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. return; } // Initialize bulk copy. if (bcp_init(hdbc, _T("myTable"), _T("myData.csv"), _T("myErrors"), DB_IN) == FAIL) { // Raise error and return. return; } if (bcp_readfmt(hdbc, _T("myFmtFile.fmt")) == FAIL) { // Raise error and return. return; } if (bcp_exec(hdbc, &nRowsProcessed) == SUCCEED) { cout << nRowsProcessed << " rows copied to SQL Server\n"; } // Carry on. ``` ## See Also [Bulk Copy Functions](../../relational-databases/native-client-odbc-extensions-bulk-copy-functions/sql-server-driver-extensions-bulk-copy-functions.md)