3

I have SQL Server Express 2012 sp2 on Windows 10, PHP Version 5.5.28, Yii Version 1.1.16, Sql Native Client 11 installed

I have followed the instructions in the following link

Enable remote connections for SQL Server Express 2012

but the following code works

<?php
$serverName = "localhost\\sqlexpress"; //serverName\instanceName
$connectionInfo = array( "Database"=>"ZDP", "UID"=>"sa", "PWD"=>"sa123123");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

but the following connection setting in Yii does not work

    'db'=>array(
        'connectionString' => 'sqlsrv:Server=localhost\\SQLEXPRESS; Database=ZDP',
        'username' => 'sa',
        'password' => 'sa123123',
    ),

and gives the following error

CDbConnection failed to open the DB connection: SQLSTATE[28000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'sa'.

Also note that the application was created using YII Version 1.1.13 but now i am transferring it to new system

Community
  • 1
  • 1
Sarwar
  • 31
  • 1
  • 4

2 Answers2

0

For anyone interested, the following string worked:

'connectionString' => 'sqlsrv:Server=localhost; Database=ZDP',
Sarwar
  • 31
  • 1
  • 4
0

Worked for me:

'db'=>array(
    'connectionString' => 'sqlsrv:server=localhost;database=mydatabase;',
    'username' => 'myusername',
    'password' => 'mypassword',
    'charset' => 'utf8',
    ),
Mundo
  • 96
  • 7