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.
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.
I have not installed sqlcmd on my linux server. Do I have to install mssql-tools on CentOS?
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:
Install php71-php-sqlsrv rpm package:
I found another issue which maybe associated with this one.
https://github.com/Microsoft/msphpsql/issues/298
Seems that maybe it is the SElinux thing. I will try to see whether it works.
@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
No luck with https://github.com/Microsoft/msphpsql/issues/298.
@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..
@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
Are sqlcmd and Laravel both on the same machine? The Login timeout expired error seems be a network error.
@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 https://github.com/Microsoft/msphpsql/issues/298, it works.
Thanks All.
Same problem here, using Laravel 5.4. Solved using IP address instead of names in database connection strings, on config/database.php.
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
Happy to help!
Most helpful comment
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