Reputation: 2856
I've setup a database connection in my config file, and if I print out the contents of Yii::app() I can find the database connection details, and they are correct.
When trying to use the Gii model generator tool, however, it falls down on me.
53 public function init() {
54 echo '<pre>';
55 print_r(Yii::app()->db);
56 echo '</pre>';
57 die();
58 Yii::app()->db = array(
59 'connectionString' => 'sqlsrv:Server=sti-hq2k8; Database=TrulinXLive',
60 'username' => 'jzumbrum',
61 'password' => 'my_super_secret_password',
62 'charset' => 'utf8',
63 'tablePrefix' => 'tbl',
64 );
65 if(Yii::app()->db===null)
66 throw new CHttpException(500,'An active "db" connection is required to run this generator.');
Exception Message:
CDbConnection failed to open the DB connection: SQLSTATE[IMSSP]: The given attribute is only supported on the PDOStatement object.
Config settings:
'db'=>array(
'connectionString' => 'sqlsrv:Server=servername; Database=database',
'username' => 'jzumbrum',
'password' => 'password',
'charset' => 'GB2312',
'tablePrefix' => 'tbl',
)
Upvotes: 2
Views: 7038
Reputation: 2856
Apparently, the issue was I could connect to the sql server on localhost. Although I'm not intimately familiar with how this server is setup, I was pretty sure that I was on a different machine, so they must have some crazy tunneling or something setup.
I find it odd that when I gave the wrong password it told me there was a connection error, but when I specified the wrong server address it gave me this other error instead. Perhaps it was resolving, just had something else blocking it that way.
Config changed to:
'db'=>array(
'connectionString' => 'sqlsrv:Server=localhost; Database=database',
'username' => 'jzumbrum',
'password' => 'password',
'charset' => 'GB2312',
'tablePrefix' => 'tbl',
)
Upvotes: 0
Reputation: 5955
From what I remember, I think I stopped having problems once I disabled emulating prepared statements:
'db'=>array(
'connectionString' => 'sqlsrv:Server=servername; Database=database',
'username' => 'jzumbrum',
'password' => 'password',
'charset' => 'GB2312',
'tablePrefix' => 'tbl',
'emulatePrepare' =>false
)
Other possible problems/ fixes available here: http://www.yiiframework.com/forum/index.php/topic/17998-use-sqlsrv-with-php-53x-and-yii/
Upvotes: 4