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 to sqlsrv : SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired #323

Closed
larryu opened this issue Mar 10, 2017 · 13 comments

Comments

@larryu
Copy link

larryu commented Mar 10, 2017

I use Lavavel 5.4 on CentOS7.2 with Php7.1.
I installed # yum --enablerepo=remi-test install php71-php-sqlsrv.
Server name, user name and password are all OK.
I can access the SQL server when I deploy my app on windows, however I cannot connect to sqlserver when I deploy the app on CentOS.
Any idea and suggestions?
Thanks.

@Hadis-Fard
Copy link

Can you connect to sql server using sqlcmd? please follow the install instructions (https://github.com/Microsoft/msphpsql/tree/dev#install-unix), install pre-requisites and then test the connectivity with sqlcmd.

@larryu
Copy link
Author

larryu commented Mar 11, 2017

I have not installed sqlcmd on my linux server. Do I have to install mssql-tools on CentOS?

@larryu
Copy link
Author

larryu commented Mar 11, 2017

BTW, I used the Remi's Repository to install the php7.1 and php-sqlsrv by following the instruction below.

Download the latest remi-release rpm from
http://rpms.famillecollet.com/enterprise/7/remi/x86_64/
Install remi-release rpm:

rpm -Uvh remi-release*rpm

Install php71-php-sqlsrv rpm package:

yum --enablerepo=remi install php71-php-sqlsrv

@larryu
Copy link
Author

larryu commented Mar 11, 2017

I found another issue which maybe associated with this one.
#298
Seems that maybe it is the SElinux thing. I will try to see whether it works.

@meet-bhagdev
Copy link
Contributor

meet-bhagdev commented Mar 13, 2017

@larryu : Were you able to connect using sqlcmd? This will help us debug the issue a little better. Here is how you can install sqlcmd:

sudo su
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-tools.repo
exit
sudo ACCEPT_EULA=Y yum install mssql-tools
sudo yum install unixODBC-devel
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

Then connect via sqlcmd

sqlcmd -S hostname -d database -U username -P password -I

@larryu
Copy link
Author

larryu commented Mar 13, 2017

No luck with #298.

@larryu
Copy link
Author

larryu commented Mar 13, 2017

@meet-bhagdev I got the following error. My SQL Server version is 2012.
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..

@larryu
Copy link
Author

larryu commented Mar 13, 2017

@meet-bhagdev New information. I reinstalled the sqlcmd based on your step. Then I can connect to the SQLServer via sqlcmd. But still cannot connect to SQL Server via Laravel 5.4.

PDOException in Connector.php line 68:
SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired

@meet-bhagdev
Copy link
Contributor

Are sqlcmd and Laravel both on the same machine? The Login timeout expired error seems be a network error.

@larryu
Copy link
Author

larryu commented Mar 13, 2017

@meet-bhagdev Yes. You are right. Seems to be a network error. I reinstalled all the driver again. Then tried to use php artisan tinker to connect to the db, that works. Then tried to use web page to connect to the db, no lucks. Then following #298, it works.
Thanks All.

@larryu larryu closed this as completed Mar 13, 2017
@chgalvez
Copy link

Same problem here, using Laravel 5.4. Solved using IP address instead of names in database connection strings, on config/database.php.

@afreeland
Copy link

Thanks @chgalvez I changed from

sqlcmd -S localhost,1433 -U SA -P {pass}

to

sqlcmd -S 127.0.0.1,1433 -U SA -P {pass}

and everything connected perfect =)

Was having this issue with OSX running docker image for SQL Server on Linux

@chgalvez
Copy link

Happy to help!

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

No branches or pull requests

5 participants