Getting unmapped SQL error code 10038 when connecting to MS SQL

While using SQL Server for your storage needs, you may encounter one of the most common error:

“Unmapped SQL error code 10038 – Attempt to initiate new SQL server operation with results pending”.

Whenever you encounter this error, try to find out the root cause of the error before solving it. This article thoroughly explains reasons and solutions of the error code: 10038.

One of the possible causes for this error is an incomplete connection to the server via a VPN and/or proxy server. If you debug the BDE code representing dialup connection to a server, you will find the the server is failing with the 10038 error. It fails whenever the single MS DBLIB function call to connect to the server. If you try to do some action against the server like executing some SQL statements (DML, DDL) they result in “Unmapped SQL error code 10038 – Attempt to initiate new SQL server operation with results pending”. 

But if you use ISQL utility to transact-SQL statements, system procedures, and script file rather than BDE code, you will find that ISQL utility try to reconnect when the initial connection appears to drop or fail whereas BDE does not do this because many of its functions rely on a continual connection to carry out supported features. But what if you have not used ISQL utility and you are reported with the error message, then what will be the solution?

Solution to resolve unmapped SQL error code 10038

There are two possible workarounds that can be implemented to resolve this error. The following points illustrate the possible workarounds:

  • Use the TDatabase param called “CANCEL QUERY” (dbcanquery). Dbcancelquery is helpful in situations when MSSQL server is unable to process a “dbcancel” of pending results which can be a reason for getting this error. But before using this feature in a TDatabase, the parameter must be added to the MSSQL driver. The parameter can be added by adding the following registry entry to the DB OPEN section of the MSSQL driver using REGEDIT.EXE

HKEY_LOCAL_MACHINE\SOFTWARE\Borland\Database Engine\Settings\DRIVERS\MSSQL\DB OPEN

Name: CANCEL QUERY Data: “”

Without making changes in the registry, the CANCEL QUERY param in the TDatabase has no affect. After you have done with the registry entry in to the MSSQL driver, use the CANCEL QUERY param to control the cancel mode

  • Use ODBC driver for establishing the connection with the server as it does not use DBLIB, which is responsible for this error.

Want to repair or restore corrupt SQL database files? Go for Kernel for SQL- efficient SQL server recovery software designed for the recovery of databases created using MS SQL server 2000 or SQL server 2005. It will repair the MDF files of SQL server and recover every database item to perform result-oriented SQL recovery.

20 queries. 0.363 seconds.