user1166689
user1166689

Reputation: 1

cakephp 2.0.5 Sqlserver requires a database connection

I'm trying to access a second MS SQL database with cakephp 2.0.5 on Linux.

I have setup an Sqlserver datasource in Config/database.php

public $msdb = array(

'datasource' => 'Database/Sqlserver',

'persistent' => false,

'host' => 'xxx.xxx.xxx.xxx',

'port' => '1433',

'login' => 'username',

'password' => 'password',

'database' => 'DB',

'prefix' => '',

);

However I get this error:

Missing Database Connection

Error: Sqlserver requires a database connection

Error: Confirm you have created the file : app/Config/database.php.

Notice: If you want to customize this error message, create app/View/Errors/missing_connection.ctp.

Stack Trace

#0 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Model/ConnectionManager.php(101): DboSource->__construct(Array)

#1 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Model/Model.php(3234): ConnectionManager::getDataSource('msdb')

#2 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Model/Model.php(1030): Model->setDataSource('msdb')

#3 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Model/Model.php(3258): Model->setSource('PERSON')

#4 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Model/Model.php(2483): Model->getDataSource()

#5 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Controller/Component/PaginatorComponent.php(172): Model->find('all', Array)

#6 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Controller/Controller.php(1025): PaginatorComponent->paginate(NULL, Array, Array)

#7 /var/www/html/modip/app/Controller/PersonsController.php(7): Controller->paginate()

#8 [internal function]: PersonsController->index()

#9 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Controller/Controller.php(473): ReflectionMethod->invokeArgs(Object(PersonsController), Array)

#10 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Routing/Dispatcher.php(104): Controller->invokeAction(Object(CakeRequest))

#11 /var/www/html/modip/cakephp-cakephp-6864406/lib/Cake/Routing/Dispatcher.php(86): Dispatcher->_invoke(Object(PersonsController), Object(CakeRequest), Object(CakeResponse))

#12 /var/www/html/modip/app/webroot/index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))

#13 {main}

Outside of cakephp I can access it without any problem using

mssql_connect("ip_addr:1433", $user, $pass);

Is there something more I should do?

I've debuged it a bit more and see that it fails in

lib/Cake/Model/Datasource/Database/Sqlserver.php in

public function enabled() {

return in_array('sqlsrv', PDO::getAvailableDrivers());

}

There is no sqlsrv in PDO drivers. If I understand correctly from varius documents,

sqlsrv is for Windows.

How can I use it for linux?

Thanks

Upvotes: 0

Views: 2733

Answers (2)

sjobe
sjobe

Reputation: 2837

I was getting this error too, it's pretty misleading. I eventually found out that the user ["username" in your case] did not have the sufficient privileges to access the database ["DB" in your case]

Upvotes: 1

mensch
mensch

Reputation: 4411

There's a "Community Technology Preview" for running the Microsoft SQL Server ODBC Driver, but I don't think it provides the functionality you need. This doesn't seem to integrate with PHP and therefore not with CakePHP.

In fact, I'm pretty certain you need the SQLSRV PHP extension, which is Windows only. You could run the MS SQL database on a Windows machine and make the data available through a script interfacing with the database and hosted on the same machine returning some form of structured output (XML, JSON, etc.). For more complex queries that approach probably won't cut it, so you would likely be looking at a simple REST API implementation.

Have a look at this question as well, there are only two answers, but they contain some interesting links detailing the problem.

Upvotes: 0

Related Questions