/// <summary>
        /// Connects using connectioninfo
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public bool Connect(ConnectionInfo info)
        {
            __dbtracelog.WriteInformation("database", "Populating database pool with connections");

            //REFERENCE OUR CONNECTION INFO
            this.info = info;

            //GENERATE A EXCEPTION QEUEE
            List<MySqlException> Exceptions = new List<MySqlException>();
            bool success = false;

            //CREATE 5 CONNECTIONS
            for (int i = 0; i < info.pooledconnections; i++)
            {
                try
                {
                    __dbtracelog.WriteLine("database", "Creating database connection: {0}", i);
                    MySqlConnectionStringBuilder cb = new MySqlConnectionStringBuilder();
                    cb.UserID = info.username;
                    cb.Password = info.password;
                    cb.Port = info.port;
                    cb.Server = info.host;
                    cb.Database = info.database;

                    MySqlConnection conn = new MySqlConnection(cb.ConnectionString);
                    conn.Open();
                    System.Threading.Timer myTimer = new System.Threading.Timer(callback, conn, 300000, 300000);
                    ConnectionPool.Release(conn);
                    success = true;
                }
                catch (Exception e)
                {
                    __dbtracelog.WriteError("database", e.Message);
                    //Exceptions.Add(e);
                }
            }

            return success;
        }
        protected override void QuerySettings()
        {
            info = new ConnectionInfo();
            try
            {
                //CONTRUCT CONNECTION INFO
                DatabaseSettings section = (DatabaseSettings)ConfigurationManager.GetSection("Saga.Manager.Database");
                info.host = section.Host;
                info.password = section.Password;
                info.username = section.Username;
                info.database = section.Database;
                info.port = section.Port;
                info.pooledconnections = section.PooledConnections;

                //DISCOVER NEW TYPES
                object temp;
                string type = section.DBType;

                if (type != null)
                    if (type.Length > 0)
                        if (CoreService.TryFindType(type, out temp))
                            if (temp is IDatabase)
                                InternalDatabaseProvider = temp as IDatabase;
                            else
                            {
                                WriteError("DatabaseManager", "No manager founds");
                            }
                        //InternalDatabaseProvider = new MysqlBackend();
                        else
                        {
                            WriteError("DatabaseManager", "No manager found, missing .dll files");
                        }
                    //InternalDatabaseProvider = new MysqlBackend();
                    else
                    {
                        WriteError("DatabaseManager", "No manager founds");
                    }
                //InternalDatabaseProvider = new MysqlBackend();
                else
                {
                    WriteError("DatabaseManager", "Cannot initialize manager");
                }
                //InternalDatabaseProvider = new MysqlBackend();
            }
            catch (Exception)
            {
                WriteError("DatabaseManager", "Cannot initialize manager");
            }
        }
Beispiel #3
0
 bool IDatabase.Connect(ConnectionInfo info)
 {
     return Connect(info);
 }