GetConnection()
- Last UpdatedNov 25, 2015
- 2 minute read
Use the GetConnection() method to request a connection to a data source.
Syntax
aaDBConnection.GetConnection(
string ConnectionString)
Parameters
ConnectionString
A previously formatted connection string or valid ArchestrA reference.
Remarks
The GetConnection() method returns a connection object to be used for subsequent SQL Server requests. Each time that GetConnection() is called with the identical connection string to a previous call, it returns the same connection object for reuse. This method is best used with a script that runs repeatedly, where a new connection object for each iteration would constitute a risk of memory leakage.
You cannot assume that a physical connection occurs after requesting a connection to a data source. Connections are opened only on an as-needed basis to perform an operation. The only time that you can check connectivity status is immediately after an operation completes.
This method immediately provides a connection object to be used for subsequent SQL requests. The first call to GetConnection() returns a unique connection object for the specified connection string, similar to CreateConnection().
Subsequent calls to GetConnection() return references to the same connection object. Thus, you can make multiple calls to reuse the same object.
The connection returned by GetConnection() is never the same object as the one returned by CreateConnection(). This difference enables you to place GetConnection() calls at the top of a script that run once per scan without constantly creating connection objects.
Note: Be sure to call Dispose() on connection objects that have been created with this method. The aaDBAccess SQLData Script Library contains a reference to the objects. Garbage collection cannot be performed on them until you call Dispose().
You can check the status of the connection by using the ConnectionState read-only property.