I need to connect from a Linux (LAMP) machine to an SQL server with mirroring.
I tried using the following but with no luck:
$dbh = new PDO("dblib:version=7.0;charset=UTF-8;host=10.37.25.2;dbname=myDataBaseName","$username","$pw", array("Failover_Partner" => "10.37.25.3:1433"));
I can connect to each server but when I try the above with the master (10.37.25.2) off I get the following error:
Failed to get DB handle: SQLSTATE[01002] Adaptive Server connection
failed (severity 9)
Any suggestions?
Related
I have running a EC2 instance with MongoDB and some .php files to deploy a little webpage.
PHP shows productos taken from MongoDB.
<?php
include_once("header.php");
require 'vendor/autoload.php';
$uri="mongodb://localhost";
$client=new MongoDB\Client($uri);
$collection = $client->tienda->categorias->find();
$categorias=array();
When I created DB it was no problem. After a new login to EC2 webpage doesn't show anything from DB.
When I try to check DB this error returns:
> use tienda
> show collections
2020-05-13T17:29:29.612+0000 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2020-05-13T17:29:29.612+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2020-05-13T17:29:29.612+0000 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
2020-05-13T17:29:29.612+0000 E QUERY [thread1] Error: socket exception [CONNECT_ERROR] for couldn't connect to server 127.0.0.1:27017, connection attempt failed :
runClientFunctionWithRetries#src/mongo/shell/session.js:346:31
runCommand#src/mongo/shell/session.js:412:25
DB.prototype._runCommandImpl#src/mongo/shell/db.js:145:16
DB.prototype.runCommand#src/mongo/shell/db.js:161:20
DB.prototype._getCollectionInfosCommand#src/mongo/shell/db.js:930:19
DB.prototype.getCollectionInfos#src/mongo/shell/db.js:953:19
DB.prototype.getCollectionNames#src/mongo/shell/db.js:964:16
shellHelper.show#src/mongo/shell/utils.js:809:9
shellHelper#src/mongo/shell/utils.js:706:15
#(shellhelp2):1:1
2020-05-13T17:24:05.117+0000 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2020-05-13T17:24:05.117+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2020-05-13T17:24:05.117+0000 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
After some google hours the only way I found to keep DB working is running on a new tab
$ mongod
Once I close this tab, DB stops to work and webpay stops to display products.
Is there any way to fix this?
I'm new to MongoDB btw.
You can run the MongoDB process as a daemon
mongod --fork --logpath /var/log/mongodb/mongod.log
Where logpath is where logs will be saved.
Documentation:
https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/
I have tested my MS SQL Server connection with this PHP code:
<?php
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number
$server = 'WIN-71KGFN2PPCC\SQLEXPRESS';
// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'test1234');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}else{
}
?>
and had this warning and error message:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: WIN-71KGFN2PPCC\SQLEXPRESS in C:\inetpub\wwwroot\index.php on line 7
Something went wrong while connecting to MSSQL
I tried many solutions, I also enabled the TCP/IP protocol of my MS SQL Server from the SQL Configuration Manager, adding the port 1433 to it and to the firewall. Any other solution to it? Please help me.
I have recently attempted to install a postgresql database on a digital ocean droplet running Ubuntu 18.04 x64
Using PgAdmin on my local PC, I can connect fine to the database.
Using my own C# tool on my local PC, I can connect fine to the database.
Using PHP on another server however, I cannot connect and upon checking the error log I have receiving this -
[19-Jan-2019 16:32:55 UTC] PHP Warning: pg_connect(): Unable to
connect to PostgreSQL server: could not connect to server: Connection
refused Is the server running on host "178.62.42.168" and
accepting TCP/IP connections on port 5432?
My PHP code is as follows, credentials adjusted for posting here but are correct.
<?php
$db = pg_connect("host=hostip port=5432 user=sam password=sensoredpassword dbname=sam ") or die('connection failed');
?>
Port 5432 is open.
I have adjusted /etc/postgresql/10/main/postgresql.conf >>> "listen_addresses = '*' and uncommented.
I have adjusted /etc/postgresql/10/main/pg_hba.conf and added >>> host all all 0.0.0.0/0 md5
Why can I not connect with PHP but I can connect with other tools and languages? Could something on the server the PHP is running on be blocking the connection?
I'm running mongodb on my local mac which was running fine in combination with MAMP. However it's not working, and when I call it in terminal, I now get this:
$ mongo
MongoDB shell version: 3.2.11
connecting to: test
2017-02-23T18:43:39.841+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2017-02-23T18:43:39.842+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
Any ideas?
Thanks!
mongo is off, you can run mongod to see where the initialization fails
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2003):
Can't connect to MySQL server on '209...' (13) in
/home/www/hookahondemond.com/Sendorder01010101010101.php on line 77
Failed to connect to MySQL: Can't connect to MySQL server on
'209...' (13)
my php code
<?php
$con=mysqli_connect("209.17.116.155","mir****","M****6","stores",'3306');
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
Login to Apache/PHP server and make sure that you can connect to the MySQL port:
telnet <mysql host> <mysql port>
If you cannot telnet the port, then it could be either one of these:
a network (firewall? routing?) problem
your MySQL server is currently not running
your MySQL host/port is incorrect
your MySQL is running but does not accept tcp connections (it has --skip-networking option set)
If you can telnet the MySQL host/port, then there is no network/MySQL setting problem,
and actually, you should be seeing a different error message (like credential error)