I have a VPS running Windows Server 2012 in a public IP. I've installed SQL Server on it and changed the firewall allowing all incoming / outcoming TCP connections on port 1433.
However when i try to connect on this server remotely from a PHP application, i get the error below :
SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist
Is there any other ports / protocols i should allow to the connection work ?
When i try to telnet the server on the port 1433 :
Connecting To xxx.xxx.xxx.xxx...Could not open connection to the host,
on port 1433: Connect failed
This solved my issue !
Enable remote connections for SQL Server:
a) In SQL Server Configuration Manager, expand SQL Server Network Configuration, and then click Protocols for <instancename>.
b) In the details pane, right-click one of the available protocols, and then click Properties.
c) To enable the TCP/IP protocol (or named pipes) for remote connections, set the Enabled box to Yes.
Related
I have a MySQL database, hosted by me on a Windows server, and I would like to query it from a remote webserver. When I try to connect to the MySQL database using PHP (I know, I should be using mysqli):
$connection = #mysql_connect("203.0.113.0:3306", "username", "password");
With or without specifying the port, after a long time of loading, I get this error with an errorno of 2003:
Can't connect to MySQL server on '203.0.113.0' (4)
Here is what I get when I run netstat -n in command prompt on the server that is hosting the MySQL server: http://pastebin.com/pbRJNqCZ. It filled up the screen so I couldn't copy everything, but I know that everything else was (I saw a couple ports with a value of 3306, which is the MySQL port):
TCP 127.0.0.1:port 127.0.0.1:port ESTABLISHED
When I run netstat -a | find "LISTENING" I get: http://pastebin.com/Lqj2BrQK
Here's what I know so far:
It isn't an error with the MySQL server not being up, because I can connect to it locally.
It isn't an error with the webserver not being able to connect to MySQL databases, because I can connect to other databases
It isn't an authentication error (The username and password are correct, and the remote server has permission)
It isn't a port forwarding error, because the port 3306 is fowarded on both TCP & UDP.
It isn't an error with being able to connect to the machine the server is hosted on, because I can ping it fine.
The server isn't only listening on the localhost interface. skip-networking and bind-address are commented out in my my.cnf file.
How could I edit my connection code, or edit my MySQL server to fix this error?
Summarizing our discussion/chat:
Bind the network address 0.0.0.0 in my.cnf: bind-address = 0.0.0.0 and ensure skip-networking is commented out or not present.
Check netstat -a | find "LISTENING"
According to your pastebin there is a service listening on 3306. Test if the port is reachable on the NIC address from the server itself. This way an external firewall does not take effect. A simple test is to try a telnet connection to that port. More detailed information can be catched by the tool nmap. Nmap has displayed the mysql port as filtered. This adverts to a problem with a local packet filter, in this case the Windows firewall.
Ensure the Windows firewall is configured to allow public access to TCP port 3306 from all or a specific machine. Setup a rule in public profile or, if both servers are controled by the same domain controller, in domain profile. When the access from local machine is successful try the same from the remote web server.
If you fail to properly configure remote access to MySql port, consider to establish a SSH tunnel between the two machines. Once established you can access to MySql as if it were on the local machine. The port is then forwarded via the tunnel and on the database server side you can access the service on localhost loopback IP.
As the title, i have problem with connection from Linux server to server with MSSQL 2012 Express.
Server with MSSQL:
Windows 8
MSSQL 2012 Express, turned on and running correctly;
IP on dyndns.org (ports on the router are correctly forwarded, 1433 is open and 'listening');
Windows firewall is disabled;
Router firewall is disabled;
Server with Linux:
PHP 5.2;
Script:
$server = 'xxxxxxx.dyndns.org';
$username = 'xxxxxxx';
$password = 'xxxxxxx';
$database = 'xxxxx';
if (mssql_connect($server, $username, $password))
{
echo "CONNECTION SUCCESS!";
}
else
{
echo "CONNECTION FAIL";
}
Result:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: xxxxxxx.dyndns.org in (....) on line 8
Connection failed: 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 Connection failed: 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 xxx.xxx.xxx.xxx:1433
I had this exact same error just now. With me it was TCP Dynamic port being used, which was not allowed through the firewall. Since it's a dynamic port, it's hard to allow just that port.
You can check by restarting your SQL server instance, and then look in the Event Viewer what port SQL Server is listening on if you have the same issue.
Open the SQL Server Configuration Manager
Then open SQL Server Network Configuration > Protocols for SQLEXPRESS(or whatever db engine you're using) > TCP/IP > IP Adresses
Make sure that in your IP adresses your TCP Port is set to the correct port you wish to use(Not entirely sure this is needed, but doesn't hurt)
Now when you come to the last item, IPAll, set TCP Dynamic ports to empty. This will disable dynamic port selection, and fill in the TCP Port you wish to use under TCP Port
Open the windows advanced firewall and allow your selected port to accept connections, if there isn't already a rule for it.
You should add a rule under Inbound rules, name it SQL port or something. Under Action "Allow the connection"
On the tab protocols and ports select Protocol type: "TCP", Local port "specific ports" "1433"(or your port number), Remote port "All ports"
and on scope any IP Adresses for local, for remote you can either choose "Any" or add a list of ip's you wish to add
Then go to your SQL Server Management Studio and hit right click on the server instant and select restart to restart the database server.
You'll get two prompts, one from uac. Then one from sql server if you're really sure you wish to restart. The second one can vanish behind other windows and can take some time to appear. So after hitting restart, be patient and don't click on stuff except the uac message.
I'm trying to connect Sql Server 2008 database with Eclipse using database source explorer,
could you help me ?
in Eclipse->
Windows ->
open Perspective ->
others ->
Database Development ->
OK
I got DataSource Explores Screen, then
in database Connection->
rightClick ->
click new ->
connection` profile will open.
In that i have selected
sqlserver->
next ->
driver details ->
i have selected sqljdbc4.jar file because iam using jdk1.6
In next tab we can see properties like connection url and driver class my doute is my system is client system i want to connect with server my server name is SQL1. But in URL there is no ServerName.
it can't establish connection
Error: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port
thank you
Seen this issue before. Copy sqljdbc_auth.dll to the working directory, should sort it.
Other than that SQL server isn't running, or it's a firewall issue. Or something else potentially is using that port.
i want to connect hosted server database through local server here is my code
<?php
$con=mysql_connect("myserverDbHostname","mydatabaseUsername","Password");
if($con)
{
echo "connect";
mysql_select_db("DatabaseName");
else
{
echo "not connect";
}
?>
when i run this file in local server (xammp server) it could n't be connect i get
Warning: mysql_connect() [function.mysql-connect]: Can't connect to
MySQL server on
i get "not connect" response
can any one guide me
Thanks for advance.
There a three things you need to connect to a remote database:
port 3306 open on the firewalls. Firewalls in server and client must open port 3306!
in my.cnf bind-address = 0.0.0.0 to let mysql bind to all interfaces
sufficient privileges in the database to allow remote connections
Virtual all hosting companies close port 3306 on the firewall, and do not allow direct remote access. And even if they do, you won't get privileges to connect to a database.
Only if the remote database is in your LAN, or you are using a VPS with root access you can configure things to make a remote connection.
I have recently configured a MySQL server on my Windows home computer. In addition, I have also created a website using 0fees.net-- a free hosting provider which comes with a vista panel that has various services including PHP support, FTP file-hosting, its own MySQL server etc.
For that website, I have created a "login" PHP script in order for people to login to my webpage. However, instead of reading from the MySQL database given to me on the cPanel on 0fees.net, I want the PHP logon script to read directly from the MySQL server that I have configured on my home computer. To do this, I have taken several steps:
1) Configured MySQL using the MySQL Server Instance Configuration Wizard
In that configuration, I have enabled TCP/IP Networking on port 3306 (and enabled a firewall exception for that port) and have enabled root access from remote machines.
2) On the MySQL command-line-client, I have granted remote access capabilities to other units by using:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY 'password';
3) I have forwarded port 3306 to my router (and have used various port checkers to confirm that it is open)
4) I have created the login script called "login.php" which lies in my site's .htdocs directory and that process an HTML login form on the homepage of my website. It attempts (and fails) to connect to my local MySQL server. The segment of interest of that php script is:
$host="my_external_ip:3306"; // External IP of my computer and port to listen on
$username="root"; // Username specified in the GRANT command-line-client command
$password="password"; // Password specified in the GRANT command-line-client command
$db_name="logon"; // MySQL database name
$tbl_name="accounts"; // Table name within the database
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die(mysql_error());
mysql_select_db("$db_name")or die("cannot select DB");
When attempting to connect to the MySQL sever, I get an error message that states:
Can't connect to MySQL server on 'my_external_ip' (4).
It should also be noted that I am successfully able to connect to my local MySQL server remotely from other machines which are on other internet networks (tested with Navicat) using this same external IP address on port 3306. Any ideas as to why my website cannot also connect?
Thanks in advance for any insights.
Since I can tell that your server is definitely running (and visible from the internets in general), there are a few possibilities:
You forgot to run FLUSH PRIVILEGES
Your username or password are wrong
Your free host provider is blocking the connection
My money is on #3, there are a lot of incentives to do that.
#Chris mentioned that your provider might be blocking outbound requests on port 3306. Here's a quick way to check if that's the case and get around it:
Configure your router to port forward from port 80 on the router to port 3306 on your box. This will allow you to connect to MySQL from outside your network on port 80 instead of port 3306.
Change your PHP code to connect to your IP on port 80 instead of 3306.
Your hosting provider might block outbound port 3306, but the almost certainly wouldn't block outbound port 80 requests (lots of people using CURL or web services and such).
Well I will let you in on a little trick I learned, all you got to do is go into wamp>mysql>my.ini and replace all 3306 with 3305 then save and then apply this to your firewall and port forward 3305. Then when you are connecting remotely, simply do
mysql_connect("ip adress:3305", "username", "password");
I've tested this and it works because the web hosting sites block incoming traffic from port 3306.