Example #1
0
        public override void Open()
        {
            if (conn_str == null)
            {
                throw new InvalidOperationException("No database specified");
            }

            if (state != ConnectionState.Closed)
            {
                throw new InvalidOperationException("Connection state is not closed.");
            }

            if (Version == 3)
            {
                sqlite_handle = (IntPtr)1;
                int flags = Sqlite3.SQLITE_OPEN_NOMUTEX | Sqlite3.SQLITE_OPEN_READWRITE | Sqlite3.SQLITE_OPEN_CREATE;
                int err   = Sqlite3.sqlite3_open_v2(db_file, out sqlite_handle2, flags, null);
                //int err = Sqlite.sqlite3_open16(db_file, out sqlite_handle);
                if (err == (int)SQLiteError.ERROR)
                {
                    throw new ApplicationException(Sqlite3.sqlite3_errmsg(sqlite_handle2));
                }
                if (busy_timeout != 0)
                {
                    Sqlite3.sqlite3_busy_timeout(sqlite_handle2, busy_timeout);
                }
                if (!String.IsNullOrEmpty(db_password))
                {
                    SQLiteCommand cmd = (SQLiteCommand)this.CreateCommand();
                    cmd.CommandText = "pragma hexkey='" + db_password + "'";
                    cmd.ExecuteNonQuery();
                }
            }
            state = ConnectionState.Open;
            this.OnStateChange(new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Open));
        }