PRB: Common Problems Using dbfcmd

Last reviewed: April 3, 1997
Article ID: Q105101

The information in this article applies to:

  - Microsoft SQL Server Programmer's Toolkit, version 4.2

SYMPTOMS

A DB-Library application fails when calling dbfcmd, or dbfcmd does not work as expected.

CAUSE

Two common situations are often the cause of dbfcmd problems:

  1. The dbfcmd function takes a variable number of parameters in params..., as can be seen be examining the dbfcmd function prototype in SQLDB.H:

          extern RETCODE SQLAPI dbfcmd(DBPROCESS *, CHAR *, ...);
    

    The lack of a complete function prototype means that a C/C++ compiler cannot perform any automatic conversion on the params... values before passing them to dbfcmd.

    Passing params... variables that do not match the types and sizes specified in the cmdstring format string can cause problems. For example, DB-Library requires far pointers to strings when %s is used, so the following code is incorrect:

         DBPROCESS *dbproc;
         char near *string;
    

         dbfcmd (dbproc, "%s", string);
    

  2. As documented under the Limitations section of dbfcmd in the Programmer's Reference for C, dbfcmd picks the maximum of 1024 and the string length of cmdstring * 2 to allocate dynamic working buffer space.

    Passing params... values that are very large in comparison to the size of cmdstring can cause problems. For example, the following code is incorrect:

         DBPROCESS *dbproc;
         char far very_large_string[1500];
    

         dbfcmd (dbproc, "%s", very_large_string);
    

WORKAROUND

The above situations can be resolved as follows:

  1. The application must ensure that the params... variable types and sizes match those specified in the cmdstring format string. In particular when %s is used:

    a. Medium model DB-Library for MS-DOS requires char near *. b. Large model DB-Library for MS-DOS, DB-Library for Windows, and

          DB-Library for OS/2 require char far *.
    
    c. DB-Library for Windows NT requires a char *.

    For example, the following DB-Library for Windows code is correct:

         DBPROCESS *dbproc;
         char far *string;
    

         dbfcmd (dbproc, "%s", string);
    

  2. If the params... values are very large in comparison to the size of cmdstring, simply use dbcmd to add these large values.

    For example, the following code is correct:

         DBPROCESS *dbproc;
         char far very_large_string[1500];
    

         dbcmd (dbproc, very_large_string);
    


Additional query words: 4.20.00 crash hang GP-Fault dblib
Keywords : kbprg SSrvDB_Lib
Version : 4.2
Platform : OS/2 Windows


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.