Knight Data Access Layer
Session Factory VB.NET
Basic Tasks VB.NET > Patterns > Session Factory VB.NET

Using The Session Factory

The session factory will instantiate a data helper and automatically load settings from the app.config or web.config file.

Add Configuration File Settings

Add settings to your web.config or app.config for the to use the Knight .NET Data Access Layer.  It is also possible to have no config file settings and simply instantiate the DataHelper and pass the provider in the constructor.   

Define the connection string normally in the config file.  Specify the DALConnectionStringName as the name in your connection string.  Specify the Provider Type using one of the Provider types below.   

<connectionStrings>

<add name="ApplicationServices" connectionString="Data Source=Invoices.vdb4;"/>

</connectionStrings>

<appSettings>

<add key="DALConnectionStringName" value="ApplicationServices"/>

<add key="DALProviderType" value="VistaDbProvider"/>

</appSettings>

 

Providers

 

Get a Session Reference

Use the SessionFactory() method to get a thread static safe session.  The session will be created once per thread.  The config settings will be retrieved when the session is created. 

 

'Get a thread static safe session

Dim db As IDataHelper = DataHelper.SessionFactory()

 

Set Licensing

The default is a 30 day trial mode.  Skip this step if you are doing a trial.  After you receive your user name and license key during the purchase process, set it.

db.UserName = "John Smith 1234"

db.LicenseKey = "a9sdkw=="