PRB: SqlBCPColumnFormat in VBSQL.OCX FailsLast reviewed: January 13, 1998Article ID: Q179166 |
The information in this article applies to:
SYMPTOMSWhen using the VBSQL function SqlBCPColumnFormat, you may receive various errors including:
"Bad DLL Calling Convention" CAUSEThe declaration for calling the SqlBCPColumnFormat function requires an array of a structure to obtain the necessary information about the columns to be copied. The structure includes a non-numeric variable length member. Visual Basic version 4.0 does not provide the capability to pass arrays of structures with variable length members to called functions.
RESOLUTIONUse the related functions SqlBCPColumns and SqlBCPColfmt instead.
STATUSMicrosoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONThe Visual Basic Library for SQL Server (VBSQL.OCX) custom control file and supporting information documents allow direct use of functions built-in to Microsoft SQL Server including bulk copy of information to and from SQL Server data sources. The function SqlBCPColumnFormat is used to identify the columns to be copied in the bulk copy process. Detailed column properties such as data types, column length, column delimiters, etc. are defined earlier in an array of the BCPColData structure. The following is an example function call:
Result = SqlBCPColumnFormat(<Connection>, <Column Data>, <NumColumns>)where - <Connection> is the SQL Connection identifier <Column Data> is the definition of the columns being copied. This information is an array of a structure BCPColData as defined in the declaration of the function. This structure has one non-numeric member. <NumColumns> is the number of column in the bulk copy.Microsoft Visual Basic for Windows version 4.0 does not provide a way to pass an array of a structure as required by the second argument <Column Data>. A workaround is to use the functions SqlBCPColumns and SqlBCPColfmt, which provide the same functionality of describing the columns to be copied:
Dim Connexion, Login, Result, RowsCopied As Long 'Initialize connection to backend Login = SqlLogin() Result = SqlSetLUser(Login, <userid>) Result = SqlSetLPwd(Login, <password>) Result = SqlBCPSetL(Login, True) Connexion = SqlOpen(Login, <Data Source Name>) 'Setup copy of Authors table in Pubs database ' to a text file c:\bulkcopy.txt Result = SqlBCPInit(Connexion, "pubs..authors", _ "c:\bulkcopy.txt", "c:\bcperr1.txt", DBOUT&) '4 columns will be copied Result = SqlBCPColumns(Connexion, 4) 'Format each column, see help topics for details Result = SqlBCPColfmt(Connexion, 1, 0, 0, -1, vbTab, 1, 1) Result = SqlBCPColfmt(Connexion, 2, 0, 0, -1, vbTab, 1, 2) Result = SqlBCPColfmt(Connexion, 3, 0, 0, -1, vbTab, 1, 3) Result = SqlBCPColfmt(Connexion, 4, 0, 0, -1, vbCRLF, 2, 4) 'Execute the bulk copy Result = SqlBCPExec(Connexion, RowsCopied) MsgBox RowsCopied & " rows were copied" 'Close connection SqlClose Connexion SqlExitThe Visual Basic Library for SQL Server (VBSQL.OCX) custom control file is available from the following sources:
REFERENCESBuilding Client/Server Applications Using Visual Basic, Chapter 8, Pages 147-148 Hitchhiker's Guide to Visual Basic and SQL Server, 4th Ed., Chapter 32, by William Vaughn. ISBN 1-55615-906-4 Keywords : APrgDataOther IAPThird PrgCtrlsCus VB4ALL VB4WIN Version : WINDOWS:4.0 Platform : WINDOWS Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |