Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection failed #190

Closed
brincas opened this issue Nov 24, 2016 · 41 comments
Closed

connection failed #190

brincas opened this issue Nov 24, 2016 · 41 comments
Labels

Comments

@brincas
Copy link

brincas commented Nov 24, 2016

hi im having this error

Connection failed to sqlsrv : SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired

The pass is correct as the server address

in main site same config (but with php5.3 and old sql server extention) everything working
but with php7 i get this error

both sites are connecting to the same place

help

@ulvii
Copy link
Contributor

ulvii commented Nov 24, 2016

Hi @brincas ,

Please provide more details, such as OS, driver (sqlsrv or pdo_sqlsrv), driver version, a repro script.

@brincas
Copy link
Author

brincas commented Nov 24, 2016

http://es-loule.edu.pt:8003/portal/teste.php

<?php
 ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

  $server['mysql']=array("dsn"=>"mysql:host=localhost;database:portal","uname"=>"portal","password"=>"password");
  $server['sqlsrv']=array("dsn"=>'sqlsrv:Server=INOVAR\INOVAR;Database=InovarAlunos;ConnectionPooling=0',"uname"=>"trunca","password"=>"password");
  $server['sqlsrv2']=array("dsn"=>'sqlsrv:Server=SIGE\MICROIO;ConnectionPooling=0',"uname"=>"sige","password"=>"password");


  $opt=array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,PDO::ATTR_TIMEOUT=>"5",PDO::ATTR_PERSISTENT => false);
  
foreach($server as $type => $dados){
    echo "<b>Connectando ao $type (DSN {$dados['dsn']})</b>: ";

    try {
        $c=new PDO($dados['dsn'], $dados['uname'], $dados['password'],$opt);
        if ( $c )echo "Conecção ao $type feita com sucesso";
        else echo "Connection failed to $type ";
    } catch (PDOException $e) {
        echo "Connection failed to $type : {$e->getMessage()} ";
    }
    echo "<br><hr><br>";
   //   unset($dbh);
}
  
  
  
  phpinfo();
  
?>`

```

@ulvii
Copy link
Contributor

ulvii commented Nov 25, 2016

PDO::ATTR_TIMEOUT, PDO::ATTR_PERSISTENT are not supported attributes.
Please see the list of supported attributes: https://msdn.microsoft.com/en-us/library/ff628164(v=sql.105).aspx

@brincas
Copy link
Author

brincas commented Nov 25, 2016

without those 2 page takes sometime to load and then:

Connectando ao sqlsrv (DSN sqlsrv:Server=INOVAR\INOVAR;Database=InovarAlunos;ConnectionPooling=0): Connection failed to sqlsrv : SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired

Connectando ao sqlsrv2 (DSN sqlsrv:Server=SIGE\MICROIO;ConnectionPooling=0): Connection failed to sqlsrv2 : SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired

@ulvii
Copy link
Contributor

ulvii commented Nov 25, 2016

are you able to connect from command line using sqlcmd?

sqlcmd -S [serverName] -d [dbName] -U [username] -P [password]

@ulvii
Copy link
Contributor

ulvii commented Nov 25, 2016

To connect to a named instance on a static port, use Server = servername,port_number
Please see: https://technet.microsoft.com/en-us/library/hh568455.aspx

@brincas
Copy link
Author

brincas commented Nov 26, 2016

from the sql command i got this:

Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2AF9.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server
is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books
Online..

@ulvii
Copy link
Contributor

ulvii commented Nov 28, 2016

Are you specifying the port? The sqlcmd command would look like this:

sqlcmd -S INOVAR,[port] -d InovarAlunos -U trunca -P password

@brincas
Copy link
Author

brincas commented Nov 28, 2016

yes with or without the port 1433 the same result :(

@meet-bhagdev
Copy link
Contributor

@brincas What version of SQL Server are you using?

@brincas
Copy link
Author

brincas commented Dec 1, 2016

to the INOVAR\INOVAR its 2008 R2, i just saw in "tcp/ip dynamic ports" nothing is set, only "Tcp Port" 1433

to the SIGE\MICROIO its 2012 but this is not important cause most likely we not gonna use their services anymore.

@brincas
Copy link
Author

brincas commented Dec 2, 2016

[ODBC Data Sources]
odbcname = MyODBC 3.51 Driver DSN

[inovar]
Driver = FreeTDS
Description = CommuniCap - Dmc
Trace = No
Servername = 192.168.10.5
Database = master

[sige]
Driver = FreeTDS
Description = My Test Server
Trace = No
ServerName = sige
Port = 1433
Database = UNICARDSIGE

DS_Version = 4.2

this is config that exists in /etc/odbc.ini

@meet-bhagdev
Copy link
Contributor

meet-bhagdev commented Dec 5, 2016

@brincas Can you confirm that you installed the ODBC Driver? I don't see it in the .ini file

@meet-bhagdev
Copy link
Contributor

@brincas, any updates from your end?

@meet-bhagdev
Copy link
Contributor

@brincas closing due to inactivity. Feel free to open if you still have the issue.

@Jamesking56
Copy link

I'm having this issue too on CentOS 7.

I get the error SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired

PDO details are correct and I can run the example script given and that connects and works fine via the CLI.

The example fails with the same error when run via Apache.

There are no config differences between PHP CLI and Apache + PHP. Any ideas why this produces different responses?

@pdrappo
Copy link

pdrappo commented Jan 12, 2017

I'm having this same issue too on Ubuntu 16.

I'm trying to connect to a SQL Server who is outside of Linux Server (It's in a Windows Server), i have a developed an application running on Windows Server with IIS and PHP, with the follow code i get a success a connection.

$db = new PDO("sqlsrv:Server=xxx.xxx.xxx.xxx\xxxxxx", $db_username, $db_password);

But when try this code on Linux server with Apache2 and PHP7 with pdo_sqlsrv installed i get the same error as the others users:

ERROR: SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired

I tryed too:

  • $db = new PDO("sqlsrv:Server=tcp:xxx.xxx.xxx.xxx\xxxxxx", $db_username, $db_password);
  • $db = new PDO("sqlsrv:Server=tcp:xxx.xxx.xxx.xxx,1433", $db_username, $db_password);
  • $db = new PDO("sqlsrv:Server=xxx.xxx.xxx.xxx,1433", $db_username, $db_password);

I hope that together can we fix this issue o figure it out whats going on.

@ziazon
Copy link

ziazon commented Feb 15, 2017

Also having this same issue and getting the same error when using sqlcmd. any help would be great..

@meet-bhagdev
Copy link
Contributor

@jubairsaidi What version of SQL Server are you using?

@ziazon
Copy link

ziazon commented Feb 15, 2017

12.0.4487.0

@pdrappo
Copy link

pdrappo commented Feb 16, 2017

Hi @meet-bhagdev i made a port test with nodejs and i seen that port 2382 was opened, so i tried to connect over that port like this:
$db = new PDO("sqlsrv:Server=tcp:xxx.xxx.xxx.xxx,2382", $db_username, $db_password);

I recived the next message:

ERROR: SQLSTATE[08001]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Client unable to establish connection because an error was encountered during handshakes before login. Common causes include client attempting to connect to an unsupported version of SQL Server, server too busy to accept new connections or a resource limitation (memory or maximum allowed connections) on the server.

My SQL Server version:
Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) Apr 2 2010 15:48:46 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1)

@meet-bhagdev meet-bhagdev reopened this Feb 16, 2017
@ziazon
Copy link

ziazon commented Feb 16, 2017

figured it out. it was a firewall issue.

@pdrappo
Copy link

pdrappo commented Feb 20, 2017

I did disabled the firewall but i'm still getting same error. Even when i try to connect to server, no logged connection on server log.

@xw43230855
Copy link

I'm having this same issue ,

sqlcmd -S 192.168.2.9/WINCC -U xxxx
I get the message:

Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2AF9.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

My SQL Server version:
Microsoft SQL Server 2008 R2 (RTM)

@pdrappo
Copy link

pdrappo commented Feb 22, 2017

I found the solution.

On my case, i was attempting to connect to a wrong port.
How i figured it out??
Thank to the follow sql query:
USE MASTER GO xp_readerrorlog 0, 1, N'Server is listening on' GO

With this query you can know wich port is MSSQL Server listening. So i tried again with the correct port and the connection was successful.

Ones again the problem was between chair and keyboard. :)

How this help to other.

@Rafabin
Copy link

Rafabin commented Mar 28, 2017

Hi @pdrappo
You can write your connection string?
I try
sqlcmd -S 192.168.2.127\LEGACY, 61945 -U sa -P xxxxx -Q "USE LEGACY" Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
The port 61945 is result of you query

@pdrappo
Copy link

pdrappo commented Mar 28, 2017

Hi @Rafabin, i would try:
sqlcmd -S 192.168.2.127,61945 -U sa -P xxxxx -Q "USE LEGACY"
Don't write the name of instance if you are on a Linux server

@Rafabin
Copy link

Rafabin commented Apr 2, 2017

@pdrappo great thanks.

@sirio3mil
Copy link

I have the same error but not always, can be with any query and only fails sometimes without a defined pattern, using CentOS7, sqlsrv (not PDO) 4.0.8.0, against and availability group.

Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) Oct 28 2016 18:17:30 Copyright (c) Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2012 R2 Standard 6.3 (Build 9600: ) (Hypervisor)

xp_readerrorlog 0, 1, N'Server is listening on'

1

connections strings

sqlsrv_connect($host, [
"UID" => $user,
"PWD" => $password,
"Database" => $database,
"ReturnDatesAsStrings" => true,
"LoginTimeout" => 5,
"CharacterSet" => "UTF-8"
])

I know that I set LoginTimeout but is not normal take more than 5 seconds. Any suggestions?

@meet-bhagdev
Copy link
Contributor

@sirio3mil Could this be a latency issue? Have you experience this when running queries with sqlcmd as well?

@sirio3mil
Copy link

I suspect that is availability group domain name network related error, I change our connection string to the IP instead of URL, I think that it's fixed.

@chrisCAD
Copy link

chrisCAD commented Apr 24, 2017

Hi @meet-bhagdev I'm getting this error from php 7.1

SQLSTATE[HYT00] SQLDriverConnect: 0 [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired

if I change connection script below to ip address rather than SAGESERVER\SAGESQL I then get

SQLSTATE[28000] SQLDriverConnect: 18456 [unixODBC][Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'web_ad'

from iSQL

isql -v MSSQLTEST web_ad xxxx
[S1T00][unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired
[08001][unixODBC][Microsoft][ODBC Driver 13 for SQL Server]MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF].
[08001][unixODBC][Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.

Any Help would be great.

Kind Regards

Chris

SQL Server version is 10.0.5512
LINUX version CentOS Linux 7.3.1611

ODBC.ini

[MSSQLTEST]
Driver = ODBC Driver 13 for SQL Server
Server = SAGESERVER\SAGESQL
Database = Sage200_DemoData
Port = 1433

ODBCINST.ini
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.6.0
UsageCount=1

PHP Script

`<?php

$mssql_server = 'SAGESERVER\SAGESQL';
$mssql_database = 'Sage200_DemoData';
$mssql_user = 'web_ad';
$mssql_password = 'xxxx';

try{
$mssql = @new PDO(
"odbc:DRIVER={ODBC Driver 13 for SQL Server}; Database={$mssql_database}; Server={$mssql_server};",
$mssql_user,
$mssql_password,
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_CASE => PDO::CASE_LOWER
)
);
} catch(PDOException $e){

if(!isset($db_status)){$db_status = array();}
$db_status['any'] 	= array( 'offline' => true );
$db_status['mssql'] 	= array( 'offline' => true, 'error' => $e->getMessage() );

echo $e->getMessage();

};

?>`

@chrisCAD
Copy link

chrisCAD commented Apr 24, 2017

I Have sorted the issue...

In the TCP/IP Config I set the IP as follows

1

but it seems this setting at the end was the port I needed to connect to 17732

2

Thanks

Chris

@sirio3mil
Copy link

Hi, @meet-bhagdev, finally our network team found the issue, connection between firewall and load balancer go through two different switches, one of them fail.

Regards

@meet-bhagdev
Copy link
Contributor

@sirio3mil That is awesome news! I will go ahead and close this issue. Feel free to re-open it if you still have issues.

@vedmant
Copy link

vedmant commented Nov 12, 2017

I started to the same error after upgrading packages my Centos 7 server, previously all worked fine, now I have:

Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

According to yum history last time update wa made on 2017-08-21, so latest packages from that date worked fine. I can't run yum history undo for some reason it shows "Failed to downgrade" for all packages. Is there any way I can find more logs from Sqlcmd or Odbc drivers?

@knbknb
Copy link

knbknb commented Apr 18, 2018

I had to find out the other portnumber SQL Server was listening on by executing

USE MASTER GO xp_readerrorlog 0, 1, N'Server is listening on' GO

add a Rule for the Windows Firewall on SQL Server host: - enabling specific Port 49155 (I think this can vary)

Then this command succeeded on my Ubuntu machine:

sqlcmd -Smyhost,49155 -U sa -P sa_pwd -d mydb -Q "select @@servername"

@michelelaferla
Copy link

I too am encountering this issue with OBDC version 17.

This is the configuration I have:

php version 7.0.30 installed on a zend engine

I have the following drivers all installed:

ODBC version 0x0380
PDO_ODBC
PDO_sqlsrv version 5.2.0
sqlsrv version 5.2.0

When trying to connect to my database using the code below, I get the error mentioned at the end.


<?php

class DB_Connect {
    private $db;

    function construct() {
    }

public function connect() {
        require_once 'String.php';

        try {
              $this->db = new PDO('sqlsrv:Server=server,port; Database=database_name', 'username', 'password');
            return $this->db;
        } catch (PDOException $e) {
            return "Error. Cannot connect to database: " . $e->getMessage();
        }
    }
?>

This is the error I get:

Error. Cannot connect to database: SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired

Can someone please help me figure out what I may be doing wrong?

@yitam
Copy link
Contributor

yitam commented May 24, 2018

Hi @mlaferla
Please check our FAQ on configuration issues
If it doesn't help, please create a new issue with more details, like how you installed the drivers, php info, etc..

@ingHainower
Copy link

hello, you can help me to the truth he verified all the possible solutions that have shown but it has not solved the problem.
I'm working with symfony 4.2 on an Ubuntu Server 18.04 server and I'm trying to find a database hosted on another Windows Server 2012 R2 server and verify the firewall and the port and that's fine.

My configuration is as follows.
.env:
DATABASE_URL=pdo_sqlsrv://mi_username_db:mi_password_db@192.168.0.120/mi_db_name

doctrine.yaml:
doctrine: dbal: # configure these for your database server driver: 'pdo_sqlsrv' server_version: '5.7' url: '%env(resolve:DATABASE_URL)%'

I run php bin / console make: migration: and I get the following error:

SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired

captura
can someone please guide me, what am I doing wrong

@yitam
Copy link
Contributor

yitam commented Dec 14, 2018

@ingHainower are you using a named instance? If so, please look at the related issue #470.

If you want further help please create a new issue and provide more details by answering the questions in the new issue template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests