microsoft / msphpsql

Microsoft Drivers for PHP for SQL Server
MIT License
1.79k stars 371 forks source link

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired. #923

Closed crisleiria closed 5 years ago

crisleiria commented 5 years ago

I am unable to connect with SQL server 2008 R2 from ubuntu 18.04 and PHP 7.2 / 7.3 latest 17.2 driver.

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.

With ubuntu 16.04, same SQL server I am able to connect... I am assuming is something with driver...

Anyone with same problem?

yitam commented 5 years ago

Hi @crisleiria

Driver version 17.2 or higher is required for Ubuntu 18.04 support. Please double check the ODBC driver version. Also, can you provide a trace?

crisleiria commented 5 years ago

I am using 17.2 version, I will get you a trace log as soon as possible. But in teory it is possible to connect to SQL Server 2008 R2 with 17.2 driver correct?

yitam commented 5 years ago

Yes @crisleiria it is supported. Please check the system requirements

crisleiria commented 5 years ago

laravel.log

Dear Yitam,

Attached is the log file from my php application, we are using Laravel Framework. I have tried sql profile trace, but it is useless, no requests reach to SQL server.

I have 100% sure that username and password is OK, we have the same source code running from ubuntu 16.04 and not problems on that envirement (driver version is 13).

Another usefull information, I have used this script to install SQL server driver on ubuntu 18.04: https://github.com/laravel/homestead/issues/610#issuecomment-430679914

yitam commented 5 years ago

hi @crisleiria

The provided link to the comment does not work, but I did skim through the comments on their issue 610.

Please enable ODBC tracing in Ubuntu 18.04 and run sqlcmd again. That is the odbc trace log I was asking for.

Can you ping the server? Login timeout may mean that you can't communicate with the server.

You might also want to try isql, like this:

isql -v -k 'Driver=ODBC Driver 17 for SQL Server;Server=<your server>;UID=<your user>;PWD=<your pass>'

Do make sure you escape special characters in the password. Yet, since you could connect from your Ubuntu 16.04 (assuming with the same credentials), I have ruled out this possibility.

crisleiria commented 5 years ago

Hi @yitam,

from isql comand I have this error:

[S1T00][unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired [08001][unixODBC][Microsoft][ODBC Driver 17 for SQL Server]MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF]. [08001][unixODBC][Microsoft][ODBC Driver 17 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. [ISQL]ERROR: Could not SQLDriverConnect

I have enable log trace, attached is the result from php website and from isql comand. odbctrace_isql.txt odbctrace.txt

I can ping sql server ip address with no problems, but it is a named instance (192.168.1.2\ABC2012). I do not have any problem on ubuntu 16.04, I dont thing this is the problem..

Thanks for the help.

yitam commented 5 years ago

@crisleiria for a named instance you will need to set it up, as explained in one of the questions in FAQ

This is the documentation for your reference.

Hope this helps.

crisleiria commented 5 years ago

Hi @yitam,

Thanks for the info, it is strange for me to setup named odbc on ubuntu 18.04.. I have nothing configured on 16.04 and I am able to connect... the only diference is the driver version...

Anyway I have setup DNS as instructions and still same error... Honestly I do not know what do to anymore...

This is a Vagrant virtual box machine.. maybe something on host machine?

yitam commented 5 years ago

@crisleiria please double check your settings. Some users are using named instance in Linux too, and #190 might be helpful.

crisleiria commented 5 years ago

I figured out... nothing related with ubuntu environment...

I review SQL server settings, TCP dynamic ports where enable, I have placed correct dinamic port assign and connected successfully. I will disable dynamic ports on SQL Server (I only have one instance running).

I dont need to setup DNS on ubuntu, if set tcp port on connection string.

Other conclusion on this: Ubuntu 18.04 is a virtual machine with a network bridge connection to the host. Ubuntu 16.04 is a real server on the same network of SQL Server.

From Ubuntu 18.04 I am only able to connect from dynamic port assign. From Ubuntu 16.04 I am able to connect without setting up port number.

@yitam Thank you so much for your support

bsor-dev commented 5 years ago

Hi @crisleiria,

Could you please share how did you placed a port assign? I have exact same issue like this, I'm using ubuntu 18.04. I tried setting up the ports on firewall still not working.

Screenshot from 2019-05-14 16-32-11

crisleiria commented 5 years ago

Hi rosnaib11,

It was notting related with ubuntu environment, it was SQL Server setting. On my case, TCP dynamic ports was enabled on SQL Server settings.

You need to set this port to your SQL connection string. On my case I am using Laravel, I needed to setup port 49300 to my connection and thats it. If not, it will try to use default port setting (1433)

Hope this helps...

image

` 'sqlsrvconnection' => [

'driver' => 'sqlsrv',

'host' => env('PHC_HOST', 'localhost'),

'database' => env('PHC_DATABASE_PRODUCTION', 'forge'),

'username' => env('PHC_USERNAME', 'forge'),

'password' => env('PHC_PASSWORD', ''),

'charset' => 'utf8',

'prefix' => '',

'port' => 49300

],`

bsor-dev commented 5 years ago

@crisleiria Thanks really helpful, I'm able to connect now.

mhunesi commented 4 years ago

Connection with telnet nor problem. But connection with PHP time out.

Ekran Resmi 2019-11-27 10 54 50 Ekran Resmi 2019-11-27 10 56 21
yitam commented 4 years ago

Hi @mhunesi

Which macOS are you using?

Have you tried using isql or sqlcmd to connect with your username and password?

samuelhgf commented 4 years ago

I'm having the same error. Timeout.

Trying to connect using php7.3 on centos 7

yitam commented 4 years ago

hi @samuelhgf we won't be able to help without more details. Please create a new issue.

angiengel91 commented 4 years ago

Hi rosnaib11,

It was notting related with ubuntu environment, it was SQL Server setting. On my case, TCP dynamic ports was enabled on SQL Server settings.

You need to set this port to your SQL connection string. On my case I am using Laravel, I needed to setup port 49300 to my connection and thats it. If not, it will try to use default port setting (1433)

Hope this helps...

image

` 'sqlsrvconnection' => [

'driver' => 'sqlsrv',

'host' => env('PHC_HOST', 'localhost'),

'database' => env('PHC_DATABASE_PRODUCTION', 'forge'),

'username' => env('PHC_USERNAME', 'forge'),

'password' => env('PHC_PASSWORD', ''),

'charset' => 'utf8',

'prefix' => '',

'port' => 49300

],`

It works for me! Thanks!! My port was different too

wasimpatel-g10 commented 2 years ago

Failed to get DB handle: SQLSTATE[HYT00]: [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired i have same issuse Screenshot (8) i able to connect with this but in code connection having issuse

$dsn = "sqlsrv:Server=(xxxxxxxxxx,1433);Database=dbname;TraceOn=true;"; $databaseName="SBOLive_ROIPLKol"; $uid="user300821"; $pwd="pswdk2011";

$conn = new PDO($dsn, $uid, $pwd,array('MultipleActiveResultSets' => false));

} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;

}

yitam commented 2 years ago

@wasimpatel-g10 please create a new issue and fill out the details