INF: Interrupting the Display of SQL Server Output
ID: Q39124
|
The information in this article applies to:
-
Microsoft SQL Server Programmer's Toolkit, version 4.2
SUMMARY
The following is a description of how to gracefully interrupt a
workstation DB-Library (DB-Lib) application from the keyboard
with CTRL+C while it is receiving data from SQL Server.
MORE INFORMATION
Set up a signal handler for CTRL+C using the C runtime function signal().
This handler should set a flag that is tested inside the dbnextrow() loop.
If the flag is set, call dbcancel() instead of dbnextrow(). This notifies
SQL Server not to send any more data and flushes anything that has already
been sent. Then bail out of the dbnextrow() loop.
This technique will not interrupt the processing of a long-running
DB-Lib function call such as dbprrow(). The signal handler will set
the flag, but the flag will not be tested until DB-Lib returns control
to the application program. A solution is to use the optional timeout
feature of DB-Lib. This will cause your error handler to get control
when the timeout period expires. Your error handler can then test
the flag set by the signal handler and return DBCANCEL if set.
The dbsetinterrupt() technique will not interrupt a DB-Lib function
when it is waiting for the SQL Server to send data because DB-Lib does
a blocked read on the named pipe. The signal handler will set the flag
(OS/2 only), but the routine registered by dbsetinterrupt() to test
that flag will not execute until the blocked read completes.
If you need to interrupt applications that are waiting for output from
SQL Server, the best approach is not to do the blocking read until the
data has arrived. Use dbdataready() to determine if data has already
been sent before calling DB-Lib functions that do blocking reads
[dbsqlexec() and dbsqlok()].
If you call dbcancel() directly from the signal handler, it may
execute while another DB-Lib function call is in progress. This can
cause DB-Lib to get out of sync with the SQL Server data stream. In
this case, DB-Lib may do a blocking read when there is nothing to be
read, causing an endless wait.
Additional query words:
dblib Windows NT
Keywords : kbprg SSrvDB_Lib SSrvProg SSrvWinNT
Version : 4.2 | 4.2 | 4.2
Platform : MS-DOS OS/2 WINDOWS
Issue type :