public SQLiteConnectionED(EDDSqlDbSelection?maindb = null, bool utctimeindicator = false, bool initializing = false, bool shortlived = true)
            : base(initializing)
        {
            bool locktaken = false;

            try
            {
                if (!initializing && !_initialized)
                {
                    System.Diagnostics.Trace.WriteLine($"Database {typeof(TConn).Name} initialized before Initialize()");
                    System.Diagnostics.Trace.WriteLine(new System.Diagnostics.StackTrace(2, true).ToString());

                    if (typeof(TConn) == typeof(SQLiteConnectionUser))
                    {
                        SQLiteConnectionUser.Initialize();
                    }
                    else if (typeof(TConn) == typeof(SQLiteConnectionSystem))
                    {
                        SQLiteConnectionSystem.Initialize();
                    }
                }

                _schemaLock.EnterReadLock();
                locktaken = true;

                // System.Threading.Monitor.Enter(monitor);
                //Console.WriteLine("Connection open " + System.Threading.Thread.CurrentThread.Name);
                DBFile = GetSQLiteDBFile(maindb ?? EDDSqlDbSelection.EDDUser);
                _cn    = DbFactory.CreateConnection();

                // Use the database selected by maindb as the 'main' database
                _cn.ConnectionString = "Data Source=" + DBFile + ";Pooling=true;";

                if (utctimeindicator)   // indicate treat dates as UTC.
                {
                    _cn.ConnectionString += "DateTimeKind=Utc;";
                }

                _transactionLock = new SQLiteTxnLockED <TConn>();
                _cn.Open();
            }
            catch
            {
                if (_transactionLock != null)
                {
                    _transactionLock.Dispose();
                }

                if (locktaken)
                {
                    _schemaLock.ExitReadLock();
                }
                throw;
            }
        }
Esempio n. 2
0
        private static void InitializeDatabase()
        {
            string dbv4file      = SQLiteConnectionED.GetSQLiteDBFile(EDDSqlDbSelection.EDDiscovery);
            string dbuserfile    = SQLiteConnectionED.GetSQLiteDBFile(EDDSqlDbSelection.EDDUser);
            string dbsystemsfile = SQLiteConnectionED.GetSQLiteDBFile(EDDSqlDbSelection.EDDSystem);

            DbFactory = GetSqliteProviderFactory();

            try
            {
                if (File.Exists(dbv4file))
                {
                    SplitDataBase();
                }

                SQLiteConnectionUser.Initialize();
                SQLiteConnectionSystem.Initialize();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error creating data base file, Exception", System.Windows.Forms.MessageBoxButtons.OK);
            }
        }