yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (127.0.0.1) (severity 9) #10749

Open dariaman opened 8 years ago

dariaman commented 8 years ago

OS : centos7 64 bit DB : SQL Server 2014 64 bit server : nginx 1.8

I have problem to connect yii2 to sql server I just use module user-management standard of extension yii2, and I had try this project on windows well. my db.php

'class' => 'yii\db\Connection',
    'dsn' => 'dblib:server=192.168.200.200,1433;database=mydb;MultipleActiveResultSets=false',
    'username' => 'sa',
    'password' => 'mypassword',
    'charset' => 'utf8',

PHP.ini

extension=mssql.so
extension=pdo.so

/etc/freetds.conf

[MSSQL]
        host = 192.168.200.200
        port = 1433
        database = mydb
        tds version = 7.0

/etc/odbc.ini (I created this file manual, not from instalation)

[TS]
Description = " database mydb"
Driver = ODBC Driver 13 for SQL Server
Server = 192.168.200.200
Port = 1433
Database = mydb

/etc/odbcinst.ini

[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/usr/local/lib64/libmsodbcsql-13.0.so.0.0
Threading=1
UsageCount=1

When I Login in web, SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (127.0.0.1) (severity 9) what should I do ?

dariaman commented 8 years ago

in terminal, not problem untitled3

dariaman commented 8 years ago

I'm sorry , I edited db.php 'dsn' => 'dblib:host=192.168.200.200;database=MGM;MultipleActiveResultSets=false',

but another error

SQLSTATE[HY000]: General error: 20018 Invalid object name 'auth_item_child'. [20018] (severity 16) [(null)]
The SQL being executed was: SELECT [child] FROM [auth_item_child] WHERE [parent]='commonPermission'
SilverFire commented 8 years ago

do you have auth_item_child table in your db?

dariaman commented 8 years ago

yes, i used extension yii2 user-management with default configuration, any one can try this module and i try in windows well without problem, and then i upload to server linux

http://www.yiiframework.com/extension/yii2-user-management/

dariaman commented 8 years ago

i know the problem, my config 'dsn' => 'dblib:host=192.168.200.200,1433;database=mydb;MultipleActiveResultSets=false', but the default database is master so the table user is unKnown, why database is not set from dsn configuration ?

i will have the other problems if I want to change database, because database of login (management user, setting auth, and etc) and database of transaction is diffrent.

I made sure, this statement not in comment

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

but, i can find the debug, maybe because nginx ?

viyancs commented 8 years ago

+1 have same problem

viyancs commented 8 years ago
$dbh = new \PDO("dblib:host=xxxxxx;dbname=xxxxx", 'xxx', 'xxxxx');

        $query = $dbh->prepare("SELECT * FROM xxxxx");
        $query->execute();
        $result = $query->fetchAll();
        var_dump($result);
            } catch (PDOException $e) {
            echo $e->getMessage();
        }

i try with this script is work, i can connect and got result of table.

viyancs commented 8 years ago

this problem maybe on db handler for sql serve 2000, in yii1 I can connect my database successfully.