public ScimoreDb() { try { IPathManager pathManager = ServiceRegistration.Get <IPathManager>(); string dataDirectory = pathManager.GetPath("<DATA>"); string databasePath = Path.Combine(dataDirectory, DEFAULT_DATABASE_FILE); const string DATABASE_NAME = "MediaPortal"; _connectionString = "Initial Catalog=" + DATABASE_NAME; _db.Create(databasePath); _db.Open(databasePath); using (ScimoreConnection conn = _db.CreateConnection(_connectionString)) { using (IDbCommand command = conn.CreateCommand()) { command.CommandText = "CREATE DATABASE IF NOT EXISTS " + DATABASE_NAME; command.ExecuteNonQuery(); } } } catch (Exception e) { ServiceRegistration.Get <ILogger>().Critical("Error establishing database connection", e); throw; } }
public override bool Initialize() { if (Initialized) { return(false); } Embedded = new ScimoreEmbedded(); Embedded.MaxConnections = 16; Embedded.MemoryPages = 3000; Embedded.MaxLocks = 1000000; var exits = Directory.Exists(Path); if (!exits) { Embedded.Create(Path); } Embedded.Open(Path); Initialized = true; using (var conn = GetConnection(true)) { if (!exits) { conn.Execute($"CREATE DATABASE {DatabaseName}"); } conn.Execute($"USE {DatabaseName}"); } return(!exits); }
public override void Init(int flowCount, long flowRecordCount) { scimore = new ScimoreEmbedded(); scimore.MaxConnections = flowCount; string dataBaseName = "test"; string dbInstanceName = String.Format(DataDirectory, "Database.scimore"); scimore.Create(dbInstanceName); scimore.OpenInProcess(dbInstanceName); connections = new IDbConnection[flowCount]; commands = new IDbCommand[flowCount]; IDbConnection connection = GetConnection(); connection.ExecuteNonQuery(String.Format("CREATE DATABASE {0}", dataBaseName)); connection.ChangeDatabase(dataBaseName); connection.ExecuteNonQuery(String.Format("DROP TABLE IF EXISTS {0};", CollectionName)); connection.ExecuteNonQuery(CreateTableQuery(CollectionName)); connections[0] = connection; commands[0] = CreateCommand(connection); for (int i = 1; i < flowCount; i++) { connection = GetConnection(); connection.ChangeDatabase(dataBaseName); connections[i] = GetConnection(); commands[i] = CreateCommand(connection); } }