Exemplo n.º 1
0
        /// <summary>
        /// Connect to database, but without synchronization
        /// </summary>
        /// <returns>True if opened</returns>
        internal bool ConnectWithoutSync()
        {
#if EVAL
            if (license == null)
            {
                license = LicenseManager.Validate(typeof(VistaDBDatabase), this);
            }
#endif

            if (databaseId > 0)
            {
                return(VistaDBAPI.ivdb_SelectDb(databaseId));
            }

            try
            {
                databaseId = VistaDBAPI.ivdb_OpenDatabase(databaseName, "", exclusive, readOnly,
                                                          (uint)parameters, password, (uint)cypher, false);
                clusterSize = VistaDBAPI.ivdb_GetClusterLength();
            }
            catch (VistaDBException e)
            {
                if (!e.Critical)
                {
                    databaseId = (int)(e.Result);
                }

                throw;
            }

            return(databaseId > 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();
            }
        }