Exemple #1
0
        /// <summary>
        /// Open a database connection to a VistaDB database.
        /// </summary>
        /// <returns></returns>
        public void OpenDatabaseConnection()
        {
            if (opened)
            {
                return;
            }

            bool       success = false;
            CypherType _cypher;
            string     _password;

            lock (syncRoot)
            {
                try
                {
                    if (cypher == CypherType.None)
                    {
                        _cypher   = CypherType.Blowfish;
                        _password = "";
                    }
                    else
                    {
                        _cypher   = cypher;
                        _password = password;
                    }

                    success = VistaDBAPI.ivsql_OpenDatabaseConnection(connectionID, dataSource, exclusive, readOnly, _cypher, _password, false);
                }
                catch (VistaDBException e)
                {
                    if (!e.Critical)
                    {
                        for (int i = 0; i < queries.Length; i++)
                        {
                            queries[i].CreateQuery();
                        }

                        opened = true;
                    }

                    throw;
                }

                if (!success)
                {
                    throw new VistaDBException(VistaDBErrorCodes.SQLDatabaseCouldNotBeFound);
                }

                for (int i = 0; i < queries.Length; i++)
                {
                    queries[i].CreateQuery();
                }

                opened = true;
            }
        }
        /// <summary>
        /// Open a database connection to a VistaDB database.
        /// </summary>
        public override void OpenDatabaseConnection()
        {
            if (this.opened)
            {
                return;
            }

            bool       success = false;
            CypherType _cypher;
            string     _password;
            int        dbID;

            lock (this.syncRoot)
            {
                try
                {
                    if (this.cypher == CypherType.None)
                    {
                        _cypher   = CypherType.Blowfish;
                        _password = "";
                    }
                    else
                    {
                        _cypher   = this.cypher;
                        _password = this.password;
                    }

                    success = VistaDBAPI.ivsql_OpenDatabaseConnection(this.connectionID, this.dataSource, this.exclusive, this.readOnly, _cypher, _password, false);
                }
                catch (VistaDBException e)
                {
                    if (!e.Critical)
                    {
                        for (int i = 0; i < this.queries.Length; i++)
                        {
                            this.queries[i].CreateQuery();
                        }

                        this.opened = true;
                    }

                    throw;
                }

                if (!success)
                {
                    throw new VistaDBException(VistaDBErrorCodes.SQLDatabaseCouldNotBeFound);
                }

                this.opened = true;

                for (int i = 0; i < this.queries.Length; i++)
                {
                    this.queries[i].CreateQuery();
                }

                dbID = VistaDBAPI.ivsql_GetCurrentDatabaseID(this.connectionID);

                this.cultureID           = (int)VistaDBAPI.ivdb_GetDatabaseCultureId();
                this.clusterSize         = VistaDBAPI.ivdb_GetClusterLength();
                this.caseSensitivity     = VistaDBAPI.ivdb_GetCaseSensitive();
                this.databaseDescription = VistaDBAPI.ivdb_GetDatabaseDescription();
            }
        }