laravel sql server connection not working - php

I'm new to the PHP framework Laravel and I wanted to connect it with my database. What I have is:
sqlsrv as default database connection
add sqlsrv configuration
Change the .env file
Added the PHP driver to connect with SQL Server
But nothing is working :( The error I get is:
SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server (2)
Anyone who knows how to solve this?
I tried MySQL and that connection worked btw ;)

In the SQL Server Configuration Manager > SQL Server Network Configuration > TCP/IP > Properties> TCP Port check if it is set to 1433. Then restart services.

If MySQL is working and not mssql, I am assuming PHP_dblib module has not been installed.
The bellow code will display installed modules.

Related

Mantis cannot connect to SQL Server

I am trying to install Mantis 2.5.1 with PHP 7.0.15 and MS SQL Server 2012. The database is already created and user has db owner permission. Pre-installation check has no errors, but when I try to install database, I get an error as:
SQLState: 08001 Error Code: 67 Message: [Microsoft][ODBC Driver 11 for
SQL Server]Named Pipes Provider: Could not open a connection to SQL
Server [67]. ....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. ...
I have checked the following already:
Named pipes is already enabled on sql server.
I have copied php_sqlsrv_7_nts_x64.dll and php_pdo_sqlsrv_7_nts_x64.dll to php extension directory, and enabled them as extensions in PHP manager in IIS 7.
Connection to sql server is possible with same credentials (tested using conn.udl)
Settings in config_defaults_inc.php
$g_hostname = 'Driver={SQLServer};SERVER=server;DATABASE=dbname;UID=username;PWD=password;';
$g_db_username = 'username';
$g_db_password = 'password';
$g_db_type = 'odbc_mssql';
What could I be missing? Pls help.
ensure that your instance is configured for SQL Server authentication.
If you change the auth mode, you need to restart the instance, which can be done in SSMS by right click to the instance name --> restart.

Cannot Connect to Azure Database through ODBC Driver 11 for SQL Server and SQL Native Client

I can easily access Azure SQL database through SQL Server 2014 but
When I am trying to connect my PHP(Laravel) web application to Azure SQL Server through ODBC Driver 11 for SQL Server and also tried with SQL Native Client 11 , it is giving me different types of exceptions as given below
[Microsoft][ODBC Driver 11 for SQL Server] A transport-level error
has occurred when receiving results from the server (provider: TCP
Provider, error: 0 - The semaphore timeout period has expired.)
[Microsoft][ODBC Driver 11 for SQL Server] A transport-level error has
occurred when receiving results from the server. (Provider: TCP
Provider, error: 0 - An existing connection was forcibly closed by
the remote host.)
[Microsoft][ODBC Driver 11 for SQL
Server]System.Data.SqlClient.SqlException: Timeout expired. The
timeout period elapsed prior to completion of the operation or the
server is not responding. The statement has been terminated.
[Microsoft][ODBC Driver 11 for SQL Server] A connection attempt
failed because the connected party did not properly respond after a
period of time, or established connection failed because connected
host has failed to respond.
[Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could
not open a connection to SQL Server [53]. , SQL state 08001 in
SQLConnect
I have gone through this Technet Article and followed all the steps successfully till step 3.
But when I traceroute to the server it is giving me following result
So, the issue which I am facing is due to reason that I am getting request timeout. And I have configured server firewall and added the client ip.
I think you can reference the article A transport-level error has occurred when receiving results from the server. People got the same error.
The possible solution is
1) Check the provider of that linked server.
2) Enable "Allow inprocess" option for that particular provider to fix the issue in provider properties.
3) For 'Packet Size=xxxxx' in connection string, try to make that 'xxxxx' shorter.
4) Try to disable "IP Offloading" on the network interfaces.
5) Restart Virsual Stdio.
6) Stopped the IIS Express and rerun your application.
Hope this can be helpful.
I have a quick test leveraging odbc_connect like:
odbc_connect("Driver={SQL Server Native Client 11.0};Server=tcp:<sqlsrv_name>.database.windows.net,1433;Database=<database>;Uid=<user>#<sqlsrv_name>;Pwd=<password>;Encrypt=yes;Connection Timeout=30;", "<user>#<sqlsrv_name>", "<password>");
However I cannot reproduce your issue. Could you please create a new Azure SQL Server, and try to connect to this new one from your local script?
If you still occur this issue, there are may be something problem with your local environment. You may check your network as your logs have shown a timeout exception.
Resolved this issue.
Problem was with the plan which I selected,it wasn't sufficient for my need.
I selected plan with higher configurations and fortunately it worked.

Laravel, Named Pipes Provider: Could not open a connection to SQL Server [2]

I'm new to Laravel framework, trying hard to check for database configuration.
Changed the host,database,username and password fields in the following files in 'sqlsrv' array
app/config/database.php
app/config/local/database.php
After enabling debug to true, ended up with the following error:
PDOException (08001)
SQLSTATE[08001]: [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [2]
Enabled the Named Pipes, TCP/IP from SQL Server Configuration Manager.
Is there anyway so that I can trace the exact problem in the database connection? Stuck finding a way to connect to sql server 2012 database with Laravel framework.

Cannot connect to SQL SERVER 2000

I am using php 5.3.1 to connect to my SQL SERVER 2000 on remote machine. I use Windows XP.
On using simple program like this:
$conn = mssql_connect("VBNET","sa","mypass") or die ( 'Can not connect to server' );
I get following error:
Warning: mssql_connect() [function.mssql-connect]: message: Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server connection. (severity 14) in C:\wamp\www\Mssql\test.php on line 8
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: VBNET in C:\wamp\www\Mssql\test.php on line 8
Can not connect to server
I enabled TCP/IP and named pipes in my SQL SERVER and restarted it. Also its Authentication is set to Mixed Mode Authentication.
I can see my server through MS SQL Server Management Studio. So what am I missing here ?
Thanks in advance.
P.S. I have another server in SQL SERVER 2008 to which I can easily connect with the same above mentioned connection string.
EDIT: According to this post, I fired sqlcmd -S np:\\VBNET\pipe\sql\query -U sa in cmd and entered the password and that worked !!! So now what could be the problem. I am at my wits end...please help !!
If you can connect using SSMS, then copy the connection exactly, i.e. make sure you specify a named instance (e.g. 'VBNET\SQLSERVER'). Open SSMS, on the server node on the left side right click and select 'Properties'.
If you have SQL 2008 running on the same machine it is most likely that SQL 2008 uses the default instance and SQL 2000 a named instance.
What also could help, i.e. make testing simpler is to create an empty UDL file (e.g. 'TEST.UDL'). An empty text file should do. Then double click on it, select the provider and play around with the settings. You can always test the connection using the 'Test connection' button. I use this trick when I have to connect from a customer PC for the first time.

Connecting to MSSQL server 2008 with PHP

We are using MSSQL server 2008 on Win server 2008 R2 and have installed Apache (2.2.19) and PHP (5.2.17) separately. We have installd the MSSQL module for PHP and usingthe following connection string:
$myc = mssql_connect(Server, SiteDatabaseUsername, SiteDatabasePassword) or die('Can\'t connect to mssql Database Server: '.mssql_get_last_message($myc));
$db = mssql_select_db(SiteDatabaseName, $myc) or die('Can\'t find database: '.mssql_get_last_message($myc));
But it gives us this error:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost\MSSQLSERVER in D:\Apache2.2\htdocs\adminarea\_core.php on line 89
Can't connect to mssql Database Server:
We have used the IP:PORT, localhost\MSSQLSERVER and COMPUTERNAME\MSSQLSERVER but don't seem to be getting anywhere, can anyone help please?
A few things come to mind:
1) Make sure you have the sqlsrv driver package from MS, and make sure you're loading it properly in php.ini (use phpinfo() to verify).
2) If this was a vanilla installation of SQL Server, its likely that only windows authentication is turned on. Open the SQL Enterprise Manager and make sure you have SQL Server Authentication enabled on your database.
3) Make sure that you have enabled network access to SQL Server. I'm not immediately certain whether the new MS drivers use named pipes to communicate with the server, or if they expect that the server will be accessed via the network.
These are the issues I routinely encounter when getting PHP speaking to a new MSSQL server.

Categories