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

            if (state != ConnectionState.Closed)
            {
                return;
            }

            IntPtr errmsg = IntPtr.Zero;

            if (Version == 2)
            {
                try {
                    sqlite_handle = Sqlite.sqlite_open(db_file, db_mode, out errmsg);
                    if (errmsg != IntPtr.Zero)
                    {
                        string msg = Marshal.PtrToStringAnsi(errmsg);
                        Sqlite.sqliteFree(errmsg);
                        throw new ApplicationException(msg);
                    }
                } catch (DllNotFoundException) {
                    db_version = 3;
                } catch (EntryPointNotFoundException) {
                    db_version = 3;
                }

                if (busy_timeout != 0)
                {
                    Sqlite.sqlite_busy_timeout(sqlite_handle, busy_timeout);
                }
            }
            if (Version == 3)
            {
                int err = Sqlite.sqlite3_open16(db_file, out sqlite_handle);
                if (err == (int)SqliteError.ERROR)
                {
                    throw new ApplicationException(Marshal.PtrToStringUni(Sqlite.sqlite3_errmsg16(sqlite_handle)));
                }
                if (busy_timeout != 0)
                {
                    Sqlite.sqlite3_busy_timeout(sqlite_handle, busy_timeout);
                }
            }
            else
            {
            }
            state = ConnectionState.Open;
        }