dbchange

DB Library for C

DB Library for C

dbchange

Determines whether a command batch has changed the current database to another database.

Syntax

LPCSTR dbchange ( PDBPROCESS dbproc );

Arguments

dbproc

Is the DBPROCESS structure that is the handle for a particular workstation or Microsoft® SQL Server™ 2000 process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.

Returns

A pointer to the null-terminated name of the new database, if any. If the database has not changed, NULL is returned.

Remarks

The dbchange function informs the program of a switch from one database to another by catching any instance of the Transact-SQL USE statement.

When connected to SQL Server version 4.2, a USE statement does not take effect until the end of the batch. The dbchange function is therefore useful only in determining whether the current command batch has changed to another database for subsequent command batches. The simplest way to keep track of database switches is to call dbchange when dbresults returns NO_MORE_RESULTS at the end of each command batch.

When connected to SQL Server 6.0 and later, a USE statement takes effect immediately.

Alternatively, you can always get the name of the current database by calling dbname.

See Also

dbname

dbsqlsend

dbresults

dbuse

dbsqlexec