CodeIgniter Forums
Database Connection Accross a Network - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Database Connection Accross a Network (/showthread.php?tid=6857)



Database Connection Accross a Network - El Forum - 03-14-2008

[eluser]polaris1927[/eluser]
I have a web server box and a database server box; connection attempts to the database server from the web server generates the error message:

Code:
An Error Was Encountered
Unable to connect to your database server using the provided settings.

It works when both web and database apps are sitting on the same server box and if I attempt to connect outside of the CI framework.

Is there a config setting for network access that I am missing?


Database Connection Accross a Network - El Forum - 03-14-2008

[eluser]polaris1927[/eluser]
I had configured the database class in the autoload.php file as follows:

Code:
$autoload['libraries'] = array('database');

Removing the class from the autoload.php file and attempting to connect to the database from the controller using:

Code:
function index()
{
    $conn = mssql_connect('srv03', 'pbx', 'pbx');

    mssql_select_db('BusinessDirectory', $conn);

    $r = mssql_query('Select * from Business_names', $conn);

    while ( $row = mssql_fetch_array ( $r ) )
    {
        echo $row['name'] . '<br>';
    }    

}

worked.

So, there seems to be a problem with the autoload.php and the database library?


Database Connection Accross a Network - El Forum - 03-14-2008

[eluser]Pygon[/eluser]
The only real difference between your code and CI's code is that CI has rawurldecode() for the hostname and such (which shouldn't cause a problem). Ofcourse, this assumes that you have
Code:
$db['default']['dbdriver'] = "mssql";
//... AND ...//
$db['default']['pconnect'] = FALSE;

or your testing isn't very valid (since CI will try to use a persistent connection, unlike your code).

Otherwise, not sure what to say -- works perfectly fine for me using a remote MSSQL database and persistant connections.


Database Connection Accross a Network - El Forum - 03-14-2008

[eluser]polaris1927[/eluser]
Thanks for the reply.

My database config is shown below:


Code:
$db['test']['hostname'] = "srv03";
$db['test']['username'] = "pbx";
$db['test']['password'] = "pbx";
$db['test']['database'] = "BusinessDirectory";
$db['test']['dbdriver'] = "mssql";
$db['test']['dbprefix'] = "";
$db['test']['pconnect'] = FALSE;
$db['test']['db_debug'] = TRUE;
$db['test']['cache_on'] = FALSE;
$db['test']['cachedir'] = "";
$db['test']['char_set'] = "utf8";
$db['test']['dbcollat'] = "utf8_general_ci";

Ruled out network connection, since I did successfully conect to the database outside of CI.


Database Connection Accross a Network - El Forum - 03-14-2008

[eluser]polaris1927[/eluser]
where can I find the code that reads the autoload.php liberies list?

Also, "rawurldecode() for the hostname" where is this defined?

THX


Database Connection Accross a Network - El Forum - 03-14-2008

[eluser]polaris1927[/eluser]
Found the solution!!

Code:
$db['test']['hostname'] = "srv03\phonedirec";

you need to get rid of the double quotes ("") and replace with single quotes (''), so that you now have:

Code:
$db['test']['hostname'] = 'srv03\phonedirec';


My database was configured as an instance, therefore I included a backslah when defining the ['hostname'] and this created a problem in CI.


Database Connection Accross a Network - El Forum - 03-14-2008

[eluser]Pygon[/eluser]
Ahh -- yes, I didn't know you were using a "\" (the escape operator). With ""(double-quotes) you should use \\ (two backslashes) to show that you want a backslash to be output.