SQLSERVER_DETACH_DB

Applies to: SQLFlex

The SQLSERVER_DETACH_DB command is intended for use with our new support of Microsoft LocalDB’s. When using LocalDB’s a common use case might be to attach to a customer DB, do some work on it, and then detach this DB and attach to a different DB. This was possible using stored procedures, but the code had some complexities that a developer need not worry about. A detach can only be done if the database passed has no open connections. As part of the detach process, the command closes ALL open files (even those not associated with this database or driver).

NOTE: SQLSERVER_DETACH_DB will often fail to execute if you are testing your application from the studio. This is because the studio itself normally has open connections to the database. If you test your application outside of the studio and the studio is closed (and any other application or tools that access this database are closed) you can successfully detach the database.

Syntax

SQLSERVER_DETACH_DB {database}

Parameter

Description

database

Name of the database

Example

SQLSERVER_DETACH_DB "TestDB"