Example #1
0
        private void CreateSqlCeDb()
        {
            var    _fileName        = "easy.sdf";
            string connectionString = string.Format("Data Source={0}", _fileName);
            var    filePath         = Path.Combine(Directory.GetCurrentDirectory(), _fileName);

            if (!File.Exists(filePath)) //File.Create(filePath,1,FileOptions.Asynchronous);
            {
                const string assemblyName = "System.Data.SqlServerCe";
                const string typeName     = "System.Data.SqlServerCe.SqlCeEngine";

                var sqlceEngineHandle = Activator.CreateInstance(assemblyName, typeName);
                var engine            = sqlceEngineHandle.Unwrap();

                engine.GetType().GetProperty("LocalConnectionString").SetValue(engine, connectionString, null /*index*/);

                //engine.CreateDatabase();
                engine.GetType().GetMethod("CreateDatabase").Invoke(engine, null);

                //engine.Dispose();
                engine.GetType().GetMethod("Dispose").Invoke(engine, null);
            }
            ConnectionManager.RegisterConnectionType(DatabaseType.SqlCe, typeof(SqlceConnection));
            ConnectionManager.SetConnection(DatabaseType.SqlCe, connectionString);
            ConnectionManager.InitManager(DatabaseType.SqlCe, 1);
            var logger = Container.Resolve <ILoggerFacade>();

            OrmManager.SetDatabase(new SqlCeDatabase(logger));
        }
Example #2
0
        private void CreateSqliteDb()
        {
            var    _fileName        = "easy.db";
            string connectionString = string.Format("Data Source={0}", _fileName);
            var    filePath         = Path.Combine(Directory.GetCurrentDirectory(), _fileName);

            if (!File.Exists(filePath)) //File.Create(filePath,1,FileOptions.Asynchronous);
            {
                System.Data.SQLite.SQLiteConnection.CreateFile(filePath);
            }
            ConnectionManager.RegisterConnectionType(DatabaseType.SQLite, typeof(SqliteConnection));
            ConnectionManager.SetConnection(DatabaseType.SQLite, connectionString);
            ConnectionManager.InitManager(DatabaseType.SQLite, 1);
            // var logger = Container.Resolve<ILoggerFacade>();
            OrmManager.SetDatabase(new SQLiteDatabase());
        }