# Opening Persistent Databases with the C# API

> As explained for In-Memory Databases, before performing data storage and retrieval operations, we must open and connect to the database. To open the database C# applications call Database method `Open()` with a number of possible parameters including a Database.Parameters object and an array of Database.Device objects. This is demonstrated in SDK sample `samples/csharp/Open`.

> To specify that the database classes are stored on persistent media, the class is declares with the attribute `[Persistent(disk=true]`. And the Database constructor must be called with `DiskSupport` enabled. For example:

>         [Persistent(disk=true)]

>         class Employee
>         {
>             ...
>         }
>         ...
>             Database.Mode mode = Database.Mode.DiskSupport;
>             Database db = new Database(mode);

> ## Defining Storage Devices

> Whereas for an in-memory database, there can be a single device to describe the conventional (aka local or in-process) or shared memory for the database, for persistent databases, or hybrid databases (which contain both transient and persistent classes), a minimum of four devices must be defined. For example:

>         const int  DATABASE_SIZE =       (600 * 1024 * 10);
>         const int  DISK_CACHE_SIZE =          (300 * 1024 * 10);

>         Database.Device devs[] = new Database.Device[4];

>         /* Configure first memory device as a plain conventional memory region */
>         devs[0] = new Database.PrivateMemoryDevice(Database.Device.Kind.Data, DATABASE_SIZE);

>         /* Configure conventional memory region for cache */
>         devs[1] = new Database.PrivateMemoryDevice(Database.Device.Kind.DiskCache, DISK_CACHE_SIZE);

>         /* Configure FILE memory device for main database storage */
>         devs[2] = new Database.FileDevice(Database.Device.Kind.Data, "opendb.dbs");

>         /* Configure FILE memory device for transaction log */
>         devs[3] = new Database.FileDevice(Database.Device.Kind.TransactionLog, "opendb.log");

> ## Database Parameters

> The database open parameters are defined in class Database.Parameters. The parameters are initialized to default values in the constructor, then the following application-specific parameters are assigned:

>         #define  MEMORY_PAGE_SIZE     128
>         #define  PSTORAGE_PAGE_SIZE   4096

>         Database.Parameters params = new Database.Parameters();

>         /* Initialize and customize the database parameters */
>         params.MemPageSize =  MEMORY_PAGE_SIZE;
>         params.Classes = new Type[] { typeof(Obj) }; // List of classes which will be stored in eXtremeDB database.
>         params.MaxConnections = 10;
>         params.DiskPageSize = PSTORAGE_PAGE_SIZE;
>         params.DiskClassesByDefault = true; // Mark [Persistent] classes as on-disk classes by default

> ## Database Operations

> Once the persistent database devices and parameters are specified, the database open method `open()`, the Connection class and all other APIs to perform database operations are identical to those for In-Memory databases. Please refer to SDK sample `samples/csharp/Open` for further implementation details.