12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

436 Day 12<br />

Key Elements<br />

TSession is the central control facility for an application’s database connections. Use the<br />

DatabaseCount property to determ<strong>in</strong>e the number of active TDatabases; use the Databases<br />

property to access them by <strong>in</strong>dex.<br />

Similar to the Database component’s DatabaseName property, the Session component’s<br />

SessionName property enables you to specify a name to publish to other components. In a<br />

multithreaded application, you would set this property to a name of your choice and then<br />

set the SessionName property of an associated Database and TDataset component (a Table,<br />

Query, or StoredProc) to match. By sett<strong>in</strong>g SessionName of a Database and, say, a Query<br />

component to match the one used <strong>in</strong> a TSession, you specify which database connection the<br />

Query is to use. By extension, if you then <strong>in</strong>teract with Query from with<strong>in</strong> a process thread,<br />

you’ve effectively specified which database connection the thread is to utilize. On some<br />

servers, this is a must because database access <strong>in</strong> one thread <strong>in</strong>terferes with that of another.<br />

The KeepConnections property determ<strong>in</strong>es whether <strong>in</strong>active database connections are<br />

reta<strong>in</strong>ed for temporary TDatabase components. Use DropConnections to drop all <strong>in</strong>active<br />

database connections. Keep <strong>in</strong> m<strong>in</strong>d that if all the current connections to a database server<br />

are <strong>in</strong>active and you drop them, you’ll have to log back <strong>in</strong>to the server the next time you need<br />

to access it. There is, however, a way to set KeepConnections to false and still avoid be<strong>in</strong>g<br />

prompted for a username and password each time the BDE reconnects to your back end.<br />

(This is covered <strong>in</strong> the discussion of the Database component later today.)<br />

The location of the BDE network control directory is stored <strong>in</strong> the NetFileDir property.<br />

Note that this is used for Paradox tables only. The directory path <strong>in</strong> which temporary files<br />

are located is stored <strong>in</strong> the PrivateDir property.<br />

Tasks<br />

Use the TSession component when you need to get at the <strong>in</strong>ternals of the BDE. You can access<br />

<strong>in</strong>formation such as alias lists, alias parameters, and driver sett<strong>in</strong>gs. You can also make direct<br />

BDE API calls us<strong>in</strong>g TSession’s Handle property.<br />

You can use the predef<strong>in</strong>ed Session <strong>in</strong>stance variable to call TSession methods. The follow<strong>in</strong>g<br />

three code excerpts are examples of TSession method calls.<br />

This method call replaces the contents of ListBox1.Items with the list of currently def<strong>in</strong>ed<br />

BDE aliases:<br />

Session->GetAliasNames(ListBox1->Items);<br />

This method call replaces the contents of ListBox1.Items with the list of all BDE and<br />

application-specific aliases:<br />

Session->GetDatabaseNames(ListBox1->Items);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!