Determines whether a command batch has changed the current database to another database.
LPCSTR dbchange ( PDBPROCESS dbproc );
A pointer to the null-terminated name of the new database, if any. If the database has not changed, NULL is returned.
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.
dbname | dbsqlsend |
dbresults | dbuse |
dbsqlexec |