Microsoft KB Archive/39124

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 16:55, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

INF: Interrupting the Display of SQL Server Output

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 : kbprogramming
Issue type :
Technology : kbSQLServSearch kbAudDeveloper kbSQLServPTK420


Last Reviewed: March 7, 1999
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.