Yii Framework Forum: Console App Issue With Mssql - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Console App Issue With Mssql Rate Topic: -----

#1 User is offline   yii_king 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 05-August 12

Posted 19 May 2013 - 03:26 PM

When using my Console application with MySQL everything works as it should. However, when I use MSSQL then I keep getting this error:

Quote

exception 'CDbException' with message 'CDbConnection failed to open the DB connection


When using createWebApplication it works with MSSQL, but not when using createConsoleApplication.

My db connection string looks like this:

Quote

'db'=>array(
'connectionString' => 'sqlsrv:server=MYSERVER\SQLEXPRESS;Database=MYDATABASE',
'username' => 'user',
'password' => 'psw',
'charset' => 'UTF-8',
),


Is this a bug or have I missed something here??
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,325
  • Joined: 21-February 11
  • Location:Greece

Posted 20 May 2013 - 03:55 PM

Hi my friend

Did you set the db connection in config/console.php or config/main.php ?
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   yii_king 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 05-August 12

Posted 20 May 2013 - 04:44 PM

I tried to set it both in config/main.php and config/console.php. Currently I have my console.php file located in the same directory as index.php. This looks like this:

Quote

// change the following paths if necessary
$yii=dirname(__FILE__).'/../../php/frameworks/yii/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

require_once($yii);
Yii::createConsoleApplication($config)->run();


Then in config/main.php I have the db connection as shown in my previous post. I also created a copy of config/main.php called config/console.php and changed the line above to point to config/console.php but that did not work.

I read somewhere that the console application is by default looking at the settings in config/console.php, but I guess that since the config dirname is defined otherwise in my file, then it is using that path instead. Any ideas of what I have missed here?

Note that there are two console.php in this case. One config file and one where the actual console app starts.
0

#4 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,325
  • Joined: 21-February 11
  • Location:Greece

Posted 21 May 2013 - 04:30 AM

View Postyii_king, on 20 May 2013 - 04:44 PM, said:

I tried to set it both in config/main.php and config/console.php. Currently I have my console.php file located in the same directory as index.php. This looks like this:



Then in config/main.php I have the db connection as shown in my previous post. I also created a copy of config/main.php called config/console.php and changed the line above to point to config/console.php but that did not work.

I read somewhere that the console application is by default looking at the settings in config/console.php, but I guess that since the config dirname is defined otherwise in my file, then it is using that path instead. Any ideas of what I have missed here?

Note that there are two console.php in this case. One config file and one where the actual console app starts.


Look at here, may be helps you
http://www.yiiframew.../topics.console

And a similar post
http://www.yiiframew...find-db-driver/
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#5 User is offline   yii_king 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 110
  • Joined: 05-August 12

Posted 21 May 2013 - 05:32 PM

The problem was caused by the fact that the wrong php.ini was being loaded for the console application. In Windows, command prompt, write php --ini and it shows which php.ini is being loaded.

In addition I had to create a separate config/console.php which only contained the db connection string (and not all other config as copied from the main.php).

Thank you KonApaz!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users