ccovey / odbc-driver

Laravel 4 ODBC Driver
28 stars 48 forks source link

Error datasource name not found #9

Closed wstaples closed 10 years ago

wstaples commented 10 years ago

Hello,

I'm receiving the error: SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified

when trying to use an eloquent model based on this driver. I'm not really sure where to begin troubleshooting. We have an installed and working odbc driver for iseries/db2. The driver is configured with UnixODBC. We are using the MySQL driver for i as well but the performance is not as good as straight db2.

Here is my model:

class ODBCCustomer extends Eloquent {
    protected $connection = 'odbc';
    protected $table = 'table_name';

}

Here is the code I'm using to create the model:

$test = ODBCCustomer::where('customer_number', '=', '12345');

And here is the relevant section of my database.php

'odbc' => array(
            'driver'   =>   'odbc',
            'dsn'      =>   'Driver={iSeries Access ODBC Driver};SYSTEM=ip_address;',
            'grammar'  =>   'DB2',
            'username' =>   'username',
            'password' =>   'password',
            'database' =>   '',
        ),
wstaples commented 10 years ago

if I var_dump the $dsn, $username, $password variables from laravel\framwork\src\illuminate\database\connectors\connector.php (around line 40) I find that they are set with the values of "odbc:odbc:datasource", "user", "password" as though it is not using the settings from database.php. If I set them manually in connector.php everything is fine. (except it breaks connection to other databases)

gsisso commented 10 years ago

thats what I use for mssql - 'odbc' => array( 'driver' => 'odbc', 'dsn' => 'Driver={SQL Server Native Client 11.0};Server=.\SQLExpress;', 'grammar' => 'SqlServerGrammar', 'username' => 'username', 'password' => 'password', 'database' => 'database', ), with my pull requests its working. a quick search over the net finds this - odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;

should be in the PDO dns,so just change it to your needs

wstaples commented 10 years ago

It looks like the application I working with chooses between several database.php files at run time based on computer name. I was not modifying the correct one. There is no issue with the odbc code.

nathan-isaac commented 10 years ago

Getting the following error: SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.

Here is a code snippet from my database.php file.

'main' => array(
            'driver'   =>   'odbc',
            'dsn'      =>   'odbc:DEV',
            'grammar'  =>   'SqlServerGrammar',
            'username' =>   '',
            'password' =>   '',
            'database' =>   '',
        )

I want to be able to use the ODBC driver manager dns connection method.

http://www.php.net//manual/en/ref.pdo-odbc.connection.php

Is there something I am missing as to why I am receiving this error?

gsisso commented 10 years ago

yes,as I mentioned above the default code doesnt work for sql server,look at my pull requests. also your dns should look something like this - 'dsn' => 'Driver={SQL Server Native Client 11.0};Server=.\SQLExpress;',

the driver part should be based on your sql server version,the one I mentioned is for 2012