Welcome Guest, Not a member yet? Register   Sign In
MSSQL Changing Database Context
#1

[eluser]whobutsb[/eluser]
For some time I have been running in to the issue where every once and a while I will receive a CI DB error that reads: "'Unable to connect to your database server using the provided settings.' So I went in to the DB_Driver.php initialize function and ran a mssql_get_last_message() function and the output read "Changed database context to 'master'.". In my php DB config file I don't have any databases named "master". I have no idea why this happens and it seems to just happen randomly whenever it pleases. So to fix the issue I added the following:
Code:
function initialize()
    {
        // If an existing connection resource is available
        // there is no need to connect and select the database
        if (is_resource($this->conn_id) OR is_object($this->conn_id))
        {
            return TRUE;
        }
    
        // ----------------------------------------------------------------
        
        // Connect to the database and set the connection ID
        $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
        // No connection resource?  Throw an error
        if ( ! $this->conn_id)
        {    
            
            $this->initialize();  //Initialize the DB again until it works!
            
            log_message('error', 'Unable to connect to the database');
            
            if ($this->db_debug)
            {
                $this->display_error('db_unable_to_connect');
            }
            return FALSE;
        }


//continues on..


This seems to fix the issue, but I have a feeling it will cause problems in the future. Any suggestions on how to fix this?




Theme © iAndrew 2016 - Forum software by © MyBB