コード例 #1
0
        /// <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();
            }
        }