Home

Vici CoolStorage - Documentation - Connection Setup

Database providers

CoolStorage supports different database providers. From version 1.2.1, it includes the following drivers:

  • Microsoft SQL Server 2000/2005
  • MS Access (Jet)
  • MySQL 5.0
  • IBM DB2
  • SQLite v3
  • VistaDB 3

Specifying the database connection should be done once in your application (or in your application configuration file). CoolStorage does not need a session to communicate with the database. Connections are opened and closed on the fly when required (it is possible to manually open a connection using the CSTransaction class, but we won't go into that now).

All database drivers support normal transactions and the TransactionScope mechanism used in the .NET Framework 2.0 and later. You should tell CoolStorage what method you want to use in your application.

CoolStorage can use different database connections for different persisted object classes (even using different data providers). This is done by specifying a context name for each persisted class. If you use more than one connection, you should tell the CoolStorage runtime what database to connect to for each context name.

Specifying your database connection in code

At the start of your application, you should add the following lines of code to connect to your database:

if (!CSConfig.HasDB())
  CSConfig.SetDB(new CSprovidername("connectionstring"));

if (!CSConfig.HasDB("contextname"))
  CSConfig.SetDB(new CSprovidername("connectionstring"),"contextname");

CSConfig.UseTransactionScope = <true|false>;

The following provider classes are available:

  • CSDataProviderSqlServer
  • CSDataProviderMySql
  • CSDataProviderDB2
  • CSDataProviderSQLite
  • CSDataProviderAccess
  • CSDataProviderVistaDB

For example, connecting to an SQL Server database "mydb" on server "mydbserver", using .NET TransactionScope transactions:

if (!CSConfig.HasDB())
  CSConfig.SetDB(new CSDataProviderSqlServer("Server=mydbserver;Database=mydb;UID=login;PWD=password;"));

CSConfig.UseTransactionScope = true;

Specifying your database connection in app.config/web.config

The easiest way to specify database connection is to add them to your application's configuration file. All you need to do is add the following to your app.config or web.config file:

<configuration>
  <configSections>
    <section name="CoolStorage" type="System.Configuration.NameValueSectionHandler"/>
  </configSections>

  <CoolStorage>
    <add key="Connection" 
         value="CSprovidername, Vici.CoolStorage.providername / connectionstring1" />
    
    <add key="Connection.contextname" 
         value="CSprovidername, Vici.CoolStorage.providername / connectionstring2" />
    
    <add key="UseTransactionScope" value="<true|false>" />
  </CoolStorage>
</configuration>

The CSprovidername is the name of the CoolStorage database driver class. Vici.CoolStorage.providername is the name of the DLL containing the driver class (e.g. Vici.CoolStorage.MySql). For example, for MySql, your config file could look like this:

<configuration>
  <configSections>
    <section name="CoolStorage" type="System.Configuration.NameValueSectionHandler "/>
  </configSections>
  
  <CoolStorage>
    <add key="Connection" 
         value="CSDataProviderMySql, Vici.CoolStorage.MySql / Server=myserver;Database=mydb" />
  </CoolStorage>
</configuration>

Another example: connecting to an SQL Server database "mydb" on server "myserver", using .NET TransactionScope transactions:

<configuration>
  <configSections>
    <section name="CoolStorage" type="System.Configuration.NameValueSectionHandler" />
  </configSections>
  
  <CoolStorage>
    <add key="Connection" 
         value="CSDataProviderSqlServer, Vici.CoolStorage / Server=myserver;Database=mydb" />
    <add key="UseTransactionScope"value="true"/>
  </CoolStorage>
</configuration>