Method DacSession():setDefault() Professional

Changes the default session of the current thread

:setDefault([lSet]) --> self
The optional argument lSet specifies whether the session is to become the new default session of the current thread. If lSet contains the value .T. (true), the session becomes the default session. Otherwise the default session is reset and the thread no longer has a default session. The default value for this parameter is .T.

The method returns the object executing the method.


Since it is possible to establish connections to more than one server using multiple instances of the DacSession class, it is necessary to specify the default session object to be used by DbUseArea()/USE or DbCreate() operations for the current thread. This is accomplished by calling the method :setDefault(), which defines a DacSession object as the default session of the current thread.

All requests for database operations created by commands and functions such as USE or DbCreate() for example, are forwarded to the server by the default session object. A default session has thread-local scope in multi-threaded programs. This means that each thread can have its own default DacSession object.

Although session objects may be accessed from different threads, doing so is strongly discouraged except for situations such as watching the connection status of another thread. Remember, sessions and therefore session objects define a transactional context for database operations. Consequently, there is no thread isolation and a rollback in one thread directly affects all other threads using the same session object. Generally, it is considered a good practice to have a session for each thread in which you plan to execute database operations.


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.