Coming from Codeigniter - Connecting to Sql Server 2005

Hi,

I’m just putting my finger on this water… so please be patient with me…

I have fully connect to a Sql Server 2005 using sqlsrv driver in Codeigniter, but can’t do the same in yii.

I’ve searched for two days now without luck.

I’ve used:


'connectionString' => "odbc:Driver={SQL Server Native Client 10.0};Server=server\\instance;Database=test;Uid=user;Pwd=pass",

'connectionString' => "mssql:host=server\\instance;dbname=test"

No luck!

any ideas?

Thank you

The docs example doesn’t mention \\instance, is that needed?

http://www.yiiframework.com/doc/guide/database.dao#establishing-database-connection

I need to use that format, server\instanse, to connect to the specified sql instance, so is a must, ¿isn’t it?

In that case, your examples show 2 slashes, while php.net shows 1 slash:

http://us2.php.net/manual/en/function.mssql-connect.php

I’ve expect to got at the end the string ServerName\Instance, yes, as you said with only one backslash, I’ve tried both. Still no luck.

In that case, are you getting any specific errors?

If so, what error?

Additionally, have you made sure you have PDO + MSSQL enabled?

http://www.yiiframework.com/doc/guide/database.dao

That might be your issue, as I’m sure codeigniter is not using PDO

I got it working in the browser but not in the cli


>> model emp

exception 'CDbException' with message 'CDbConnection does not support reading schema for odbc database.' in D:\webroot\yii\framework\db\CDbConnection.php:399

I can live with that, I’ve used:


odbc:Driver={SQL Server Native Client 10.0};Server=ServerName\\Instance;Database=testdb;

Thank you for your orientation.

rricardo, if ODBC is working but not mssql directly, I’ll bet your PHP PDO doesn’t have mssql enabled. If you fix that, it would likely correct your cli issue

This is the output of the phpinfo()

557

phpinfo().jpg

ha, you got me there :slight_smile:

at least that suggests it’s not your setup, but instead a possible Yii issue.

Did you ever see any error output when you were attempting the regular mssql connect string?

if I use:


'connectionString' => 'mssql:host=serverName\\Instance;dbname=testdb;'

I got Fatal error:


Maximum execution time of 60 seconds exceeded in D:\webroot\yii\framework\db\CDbConnection.php on line 0

and in cli:




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

SQLSTATE[01002] Unable to connect: SQL Server is unavailable or does not exist.  

Specified SQL server not found. (severity 9)' in D:\webroot\yii\framework\db\CDbConnection.php:262

Sad, I do my first model extending CActiveRecord, and got:

559

CDbException.jpg

rricardo, why not instead try a SQLite instance? just so you can get developing.

You’re running PHP on your localmachine currently, right? So when you’re ready to go to the actual server, you can then change to mssql (as it’ll likely work better in php on linux than on windows, as the windows mssql driver is iffy per php.net).

If you think it could be a bug, please open a bug report http://code.google.com/p/yii/issues/list

I’ll take that in account. Thank you.

intel352, thank you for your support. Actually because is an integration to an Enterprise ERP, I do prefer to fight with sql server. I went back to Codeigniter and it is running well. I hope to be here soon.

I tried this, (single backslash before the ‘instance’):

‘connectionString’ => “mssql:host=server\instance;dbname=test”

and it worked fine.

I too am coming from Codeignitor and it took me 10 hours to figure this out!!

Hi rricardo! I’m sorry but can you give me steps on how to connect Codeigniter to Sql Server 2005 with ODBC? Because it keeps failing when I tried whereas I already followed steps from other forums, and from there I can summarize that:

  1. change the dbdriver in application/config/database.php to odbc

  2. remove apostrophes around the table names in _from_tables($tables)function in system/database/drivers/odbc/odbc_driver.php

The error is:


Unable to connect to your database server using the provided settings.


Filename: C:\wamp\www\ci\system\database\DB_driver.php


Line Number: 124