Using statement
The
using
statement enables you to use a correct syntax with the
appropriate use of objects that must be released or disconnected. In this example, the connection is closed automatically at the end of the
using
statement block:
using (OLAPConnection conn = OLAPCreateNamedConnection("dataConnection"))
{
// work with the connection
}
You can use multiple using
statements, for example:
using (SQLConnection conn = SQLCreateNamedConnection("dbAlias"))
using (SQLPreparedCommand cmd = SQLCreatePreparedCommand(conn, "SELECT * FROM MyTable"))
{
SQLData dt = cmd.ExecuteQuery();
// process the result set
}
Variables declared in a using
statement are valid only in this statement.
This table shows possible runtime types that are supported in using
statements:
Runtime type | Closing function | Comments |
---|---|---|
OLAPConnection |
OLAPDisconnect |
Not pooled connections |
OLAPConnection |
OLAPReleasePooledConnection |
Pooled connections |
SQLConnection |
SQLDisconnect |
|
XMLAConnection |
XMLADisconnect |
|
SQLPreparedCommand |
SQLReleaseCommand |
|
RedshiftConnection |
SQLDisconnect |
|
RepositoryConnection |
RepositoryDisconnect |
|
BinaryData |
BinaryDataRelease |