Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Connections

Daniel Wertheim edited this page Nov 29, 2012 · 6 revisions

To start interact with SisoDb databases, you need a connection. You achive this by passing an implementation of ISisoConnectionInfo to an ISisoDbFactory:

var cnInfo = new Sql2012ConnectionInfo(@"normal connectionstring or name");
var db = new Sql2012DbFactory().CreateDatabase(cnInfo);

Helpers

There are some extension methods making it easier for you. All you have to do is define the connectionstring or a connectionstring name entry, and then call CreateAzureDb() | CreateSql2005Db() | CreateSql2008Db() | CreateSql2012Db() | CreateSqlCe4Db().

var db = "connectionstring | connectionstringname".CreateSql2012Db();

When using any of the constructs, it doesn't really create the database, it creates an instance of ISisoDatabase that you use to interact with your database.

SQLCE4 in web scenario

To make use of an SQLCE4 database located in App_data you would use a connectionstring like this:

var cnInfo = new SqlCe4ConnectionInfo(@"Data source=|DataDirectory|sisodb.sdf;");

Resolve via ConnectionStringName

Instead of passing in the actual connectionstring you could of course also pass in the connectionstringname and SisoDb will try look it up in the Config-file. It will first try and resolve it by automatically prefixing the sent connectionstringname with "MACHINENAME_". If nothing could be resolved it will fallback to whatever you passed in.

Code executed on computer named "TeddyBear":

var cnInfo = new SqlCe4ConnectionInfo("myFooDb");

will match:

<connectionStrings>
  <add key="TeddyBear_myFooDb" value="....." />
</connectionStrings>

and if that wasn't present it will match:

<connectionStrings>
  <add key="myFooDb" value="....." />
</connectionStrings>
Clone this wiki locally