MSSQL 服务器未在代码点火器中配置.即不建立连接


MSSQL server not configuring in codeigniter. i.e. not establishing a connection

我在代码点火器中与数据库建立连接时遇到问题。我已经尝试了很多,并测试了不同人给出的许多解决方案,但到目前为止还没有成功。

我在编码点火器中的配置是:

$db['default']['hostname'] = 'DX-PC'MSSQLSERVER';
//$db['default']['port'] = 1433;
$db['default']['username'] = 'myusername';
$db['default']['password'] = 'mypass';
$db['default']['database'] = 'mydbname';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE; //default: TRUE
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

所以,它给了我以下错误:

发生数据库错误 无法使用提供的设置连接到数据库服务器。

同样,我使用以下代码尝试了与MS SQL服务器的连接建立,而无需使用代码点火器:

    echo 'called';
    echo "<br>";
    $serverName = "DX-PC''MSSQLSERVER"; //serverName'instanceName
    $connectionInfo = array( "Database"=>"mydbname", "UID"=>"myusername", "PWD"=>"mypass");
    $conn = sqlsrv_connect( $serverName,$connectionInfo);
    if( $conn ) {
        echo "Connection established.<br />";
    }else{
        echo "Connection could not be established.<br />";
        echo "<pre>";
        print_r(sqlsrv_errors());
        echo "</pre>";
    }

它给了我这些错误:

called Connection could not be established.
Array
  (
    [0] => Array
       (
        [0] => 08001
        [SQLSTATE] => 08001
        [1] => 87
        [code] => 87
        [2] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. 
        [message] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. 
    )
[1] => Array
    (
        [0] => HYT00
        [SQLSTATE] => HYT00
        [1] => 0
        [code] => 0
        [2] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
        [message] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
    )
[2] => Array
    (
        [0] => 08001
        [SQLSTATE] => 08001
        [1] => 87
        [code] => 87
        [2] => [Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
        [message] => [Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
    )

我已经尝试了来自不同论坛和堆栈溢出的所有解决方案,但没有成功。请帮助我。谢谢

过去我也有问题,所以我用经典的方式做了:

$server = "x.x.x.x'MSSQL2005,1435";
$user = "xxxx";
$pass = "xxxx";
$this->ms  = mssql_connect($server, $user, $pass) or die ("No connection");

是的,我已经想通了,它现在可以工作了。以下更改使其正常工作。

  1. 以前的配置,你必须做过,以前,即(扩展:sqlsrv_*.dll等在php中添加.ini等)

  2. 从重写规则 ^(.) 更改 .htaccess 中的重写规则$/index.php?/$1 [L] to RewriteRule ^(.)$/yourrootfolder/index.php?/$1 [L] (由SHAZ提供)

  3. 其次,由于我有一个名为 MSSQLSERVER 的默认实例,因此它不需要写入 $db['default']['hostname'] = 'DX-PC''MSSQLSERVER'; 而是写$db['默认']['主机名'] = 'DX-PC';

我希望这可以帮助其他人。谢谢。