Here is my connection string.
public $default = array(
'datasource' => 'Database/Sqlserver',
'persistent' => false,
'host' => 'SAI-PC\\SQLEXPRESS',
'login' => 'sa',
'password' => '123',
'database' => 'SFAC_Connectmp',
'prefix' => '',
//'encoding' => 'utf8',
);
I am able to login the sql server using the above credentials and it works fine
I have checked all the options from the sql server manager.
eg. -Sql server and browser services are running fine.
-Remote server connection is checked
-windows firewall is off
-Still i get the error
A Database connection using "Sqlserver" was missing or unable to connect.
The database server returned this error: SQLSTATE[08001]: [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [2].
Could it be the host name?
Try adding the port to the host with hostname:port
Is the server local? Does it work with localhost?
Is it on the local network? Does it work with it's LAN ip?
Have you installed/enabled the php sqlsrv driver?
Try this
Related
I can`t find too much documentation about connecting Drupal7 website with SQL Google database. Does anybody have experience with it? I trying to split Drupal website on VM instance and mysql database on SQL Google storage. After that, change settings.php in Drupal:
$databases['default']['default'] = array(
'database' => 'DATABASE',
'username' => 'USERNAME',
'password' => 'PASSWORD',
'host' => 'Public_IP_of_Google_SQL',
'driver' => 'mysql',
'port' => 3306 (I try 1433 also),
'prefix' => '',
);
}
On SQL instance I have enabled firewall for tcp ports:3306,1433
However, I always get error
PDOException: SQLSTATE[HY000] [2002] Connection refused in lock_may_be_available() (line 167 of /home/public_html/includes/lock.inc).
Can anybody help? What can I do on Drupal side to connect website with external database?
unfortuantely i have to make laravel talk to sql server .. i normally use mysql.. and have developed a swift hatred for sql server..
i'm running xampp on localhost for development. I can connect and query to local sql server fine with navicat and with sql server management studio.
sqlsrv_connect works fine in php, and i can run queries manually with no problem.
mssql_connect works fine in php, and i can run queries manually with no problem.
but laravel fails.
in env:
DB_CONNECTION=sqlsrv
DB_HOST=localhost
DB_DATABASE=handheld2
DB_USERNAME=handheld
DB_PASSWORD=thepasswordhere
DB_PORT=1433
and in laravel database config:
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL', 'localhost'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'handheld2'),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
]
i'm not clear what 'url' is for? how is this different to db_host ?
i receive
Illuminate\Database\QueryException
SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.
both php_sqlsrv_72_ts_x64.dll and php_pdo_sqlsrc_72_x64.dll are enabled in php
am i missing something simple and obvious?
edit: note that this code works
$connectionInfo = array(
"Database"=>"handheld2",
"UID" => "handheld",
"PWD" => "thepasswordhere",
);
$conn = sqlsrv_connect("localhost", $connectionInfo);
if ($conn === false) {
echo "Could not connect.\n";
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query($conn, 'SELECT top 1 * from users where users.id = 1');
if($stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
while( $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) ) {
print_r($row);
}
and prints out record from db.. so why does it work here but not though laravel ???
debugging in laravels files in vendor.. turns out it was trying to connect to 'andheld2' instead of 'handheld2'
changing
'url' => env('DATABASE_URL', 'handheld2'),
to
'url' => env('DATABASE_URL', '/handheld2'),
in the database config makes it work.. it apparently ignores the first character.. for some reason? whatever.
It’s an old question but we had the same problem with the sqlsrv php driver. This was caused by the dynamic ports of the sql server - switching to specific port solved the problem for us.
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-a-server-to-listen-on-a-specific-tcp-port
If anyone else finds themselves here maybe this will help.
After hours of banging my head against the wall, the fix for me in the end was extremely simple. I was working with a fresh install of everything (including Sql Server) and I had to open Sql Server Configuration Manager (which itself is a pain in the butt in Windows 10...I ended up having to just search in the windows folder for SQLServerManager because I didn't know the exact version number, which was 15).
Then > SQL Server Network Configuation > Protocols for MSSQLSERVER > TCP/IP was disabled. Enabled this, restart SQLSERVER in Windows Services and viola, laravel works.
For me the solution was to remove the port in the .env file
It has something to do with dynamic ports.
same as mentioned in other comments.
My code in .env
DB_CONNECTION=sqlsrv
DB_HOST=USERNAMESERVE\SQLEXPRESS
DB_PORT=
DB_DATABASE=DB_NAME
DB_USERNAME=sa
DB_PASSWORD=sa
I'm getting this error when trying to connect to an SQL Server DB from Laravel 4.2.
Here's my DB config:
'connections' => array(
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'example.noip.me',
'database' => 'db',
'username' => 'sa',
'password' => 'pass',
'prefix' => '',
),
),
//...
It works perfectly in my home computer, but not in production. This project is in a hosting service, so I can't change much of the config (can still use ini_set though).
I tried adding the port to the server address but it didn't work.
Edit: I forgot to mention that the hosting and the database server are on different computers, so it could be a security configuration problem.
I contacted tech support and it turned out to be a matter of configuration in the hosting server (Remote Database Access Hosts, which I thought was for MySQL only).
Okay so i am trying to connect to my remote SQL database.
i am using the following settings:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => '10.246.16.153:3306',
'login' => '*******',
'password' => '*******',
'database' => 'udlejnings_pris',
'prefix' => '',
//'encoding' => 'utf8',
);
My Database settings are the following:
Database server
Server: 10.246.16.153 via TCP/IP
Software: MySQL
Software version: 5.1.66-0+squeeze1 - (Debian)
Protocol version: 10
Server charset: UTF-8 Unicode (utf8)
Now when im trying to access this server i get the following error:
2013-10-12 16:27:28 Error: [MissingConnectionException] Database connection "Mysql" is missing, or could not be created.
Exception Attributes: array (
'class' => 'Mysql',
'message' => 'SQLSTATE[HY000] [2002]
',
'enabled' => true,
)
So what am i doing wrong?
Many hosted MySQL instances don't allow clients to connect remotely by default. You may need to add your IP address into some form of Remote MySQL option if your database host provides it. For example, if the server with the database on it uses cPanel, there is a 'Remote MySQL' option on there which may resolve your issue. Alternatively, you could execute the 'GRANT' SQL command to allow your user account access remotely as described in this answer.
If you still have issues, a firewall may be blocking the connection locally too.
Maybe you need to enable mysql remote access on the server that you are connecting to. By default it is disabled.
http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
I want to connect to an external Database on another Host (not localhost) on Drupal because i want to migrate Content with the Migrate Module.
thats in my settings.php
$databases['for_migration']['default'] = array(
'driver' => 'mysql',
'database' => 'dbname',
'username' => 'username',
'password' => 'password',
'host' => 'other-host.com',
'prefix' => '',
'port' => '',
);
And in another method im calling the database via:
$query = Database::getConnection('default', 'for_migration')
thats the error which appears:
PDOException: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'host.com' (13) in MigrateMigration->__construct() (Zeile 16 von /var/www/html/x/sites/all/modules/migrate_x/x.inc).
So if i call a database on localhost, there are no errors and all migrates perfectly. But i cant connect to a database on an external host.
That could be due to:
1) connection limitation (firewall block, for example).
2) the account you are using does not allows logins outside of "localhost". In this case, you will have to edit your account hostname mask on the 'user' table inside the 'mysql' database for '%' (which means, any address) or the machine IP address you are accessing from.
It was my fault. I have set httpd_can_network_connect on the remote server to on.
But the solution was to set it on my local machine. After that i can connect to an external Host. So it was a SELinux Problem.
Thanks to #fobia