Search scimore.com

ScimoreDB Connection String WalkThrough

The Scimore Database engine can be used in different ways. In all cases, connection string can be used to connect and possibly start a database instance.

Using the connection strings we here explain how the different modes of instantiation works.

Querying Scimore Database

You have propably seen this code many times, but to set the right context here it is. Connecting and querying to a database server using ADO.NET.

        using Scimore.Data.ScimoreClient;
        string ConnectionString = 
            "...";
        using( ScimoreConnection cn = new ScimoreConnection( ConnectionString)) 
        {
            cn.Open();
            ScimoreCommand cm = new ScimoreCommand( "select * from ..", cn);
            ScimoreDataReader dr = cm.ExecuteQuery();
            ...
        }
    

Now lets get started. Change the connection string and see the effects!

WinForm Application: Out of process

        string ConnectionString = "Data Source=" + 
            Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\MyDB";
    

Using this connection string, you will start a seperate process with your database instance. One database instances can contain many databases - similar to an normal sql server. All applications using this connection string will connect to the same database instance, enabling multiple applications accessing the same data.

The database runs very much as if standalone database server, but its not installed as a server. In process viewer, you will see a "rundll.exe".

Note, that it is not recommended to start a database over a file share.

Web Application: In Process

        string ConnectionString = 
            "Open Mode=Exclusive;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "App_Data\\GetStartedIn3Minutes";;
    

Put an database inside your application. Using shared memory for communication, and is thus very fast. It can't be access from outside the web server, e.g. by the manager. And if the application dies, the database instance will terminate.

You can fine tune the database startup parameters, so it fits your application, by using the following parameters:

Max Buffer Size=xxx Number of 8Kb pages to allocate
Max Connections=yyy Maxiumum allowed number of connections
Max Locks=zzz Number of allocated page level locks

Connecting to a ScimoreDB Server service

        string ConnectionString = 
            "Server=localhost; Port=999; Database=northwind";
    

Connect to a database instance running as a windows service, and setting the default database.

Connecting to multiple servers

        string ConnectionString = 
            "Server=10.0.0.2&10.0.0.3; Port=999; Default Database=Northwind";
    

Or you can specify port pr. server by using:

        string ConnectionString = 
            "Server=10.0.0.2:999&10.0.0.2:1000; Default Database=Northwind";
    

Allow load balancing over multiple database instances. Switches between the different database server for each new connection. In this case, first query goes to 10.0.0.2, second to 10.0.0.3, third to 10.0.0.2, and so on. Good for fault tolerance, and for distributing read queries over many database servers. Database might be replicated between instances using replication.

Connecting to distributed cluster

        string ConnectionString = 
            "Server=10.0.0.2; Port=999; Default Database=northwind";
    

A distributed cluster is a set of machines, which acts as a single database instance. It works transparently, distributing data and queries over the machines in the distributed cluster.

Connecting to a distributed cluster, is similar to connecting to a single database instance. You can connect to any instance in the cluster and it will execute your query.

This type of scenario is good for clusters with massive updates, or large databases that needs to be distributed over many machines. Read more about a href="/products/distributed.aspx"> ScimoreDB Distributed.

ScimoreEmbedded API

Connection strings is not the only way to connect to a Scimore Embedded Database.

With the ScimoreEmbedded class you get administration. With this object you can create databases, stop and start database instances. In the 3 minutes getting started samples, the usages of the object is demonstrated.

        ScimoreEmbedded em = new ScimoreEmbedded();
        em.Create(@"c:\database\sample1");
        em.Open(@"c:\database\sample1");

This will launch the database as an external process, what we call "out of process". The ScimoreEmbedded em variable should be global and reused for each thread needed a connection.

Multiple application using the same Create and Open path, they will share the same database instance, all connecting the started embedded database process. The embedded process will shut down automatically, 1 minute after the last application disconnects.

        ScimoreEmbedded em = new ScimoreEmbedded();
        em.Create(@"c:\database\sample1");
        em.OpenInProcess(@"c:\database\sample1");

This will load the database inside the calling processed, and enforce exclusive access the database by the current processed. This mean you wont be able access the database from other applications, e.g. the manager - while your application is running.

Using the embedded object it's possible to explicitly shutdown the database process

        em.Shutdown();