dbchange

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

Syntax

LPCSTR dbchange ( PDBPROCESS dbproc );

where

dbproc
Is the DBPROCESS structure that is the handle for a particular workstation/ SQL Server 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 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, a USE statement takes effect immediately.

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

See Also

dbname, dbresults, dbsqlexec, dbsqlsend, dbuse