Microsoft KB Archive/105101

= PRB: Common Problems Using dbfcmd =

Article ID: 105101

Article Last Modified on 3/14/2005

-

APPLIES TO


 * Microsoft SQL Server 4.21a Standard Edition
 * Microsoft SQL Server 6.5 Standard Edition

-



This article was previously published under Q105101



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:

  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);

  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:

  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:

 Medium model DB-Library for MS-DOS requires char near *. Large model DB-Library for MS-DOS, DB-Library for Windows, and DB-Library for OS/2 require char far *.</li> DB-Library for Windows NT requires a char *.</li></ol>

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

DBPROCESS *dbproc;

char far *string;

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

</li>  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);

</li></ol>

Additional query words: 4.20.00 crash hang GP-Fault dblib

Keywords: kbprogramming KB105101

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.