I have done a small C# Win Forms application, that connects to mySQL database using mySQLconnector. This works perfectly ok with my localhost.
String ConnectionString = "server=xx.xxx.xx.xxx;uid=myuserid;pwd=mypassword;database=dbname";
But I do get following error when I try to connect to remote server:
Unable to connect to any of the specified MySQL hosts.
{"No connection could be made because the target machine actively refused it xx.xxx.xx.xxx:3306"}
I have pinged the server from command prompt and I get response.
I also verified mySQL server settings in remote server database (correct name/ip, portno:3306, skip networking:OFF)
The remote server is accessible without any problem from web server that runs php script and uses same settings as the connection sting I listed above.
The mySQL server is hosted on external shared hosting company 123reg.co.uk with me logging to phpmyadmin using same uid/passwd as like in connection string.
I can't understand what is different between webserver accessing OK, but my C# app having trouble with it??
Can any one please help...
Thanks in Advance
Sam
I've had issues with servers setup so they won't accept remote connections. This is for security reasons mainly. Some places will let you enable it in the CP, but if you have direct access to the server, you should be able to follow these steps.
http://www.rackspace.com/knowledge_center/article/mysql-connect-to-your-database-remotely
Your ip address will be different from the web server.
If your ip address is static you can grant access to your ip address within your mysql database ( https://www.google.com.au/search?q=mysql+grant+access+to+user+from+host ).
I'd recommend using the server to access the database and make your c# application talk to your webserver using ajax/json calls ( https://www.google.com.au/search?q=C%23+Win+Forms+ajax+json ) - that way you're not tied to an ip address for access.
Alternatively you can look at setting up ssh tunnels to your webserver if remote shell access is available so you can get the same access as your webserver. ( https://www.google.com.au/search?q=ssh+tunnels+example+mysql That's what I do myself)
Related
I have added a database via phpmyadmin on a server. I can access it via http://ipaddress/phpmyadmin . but when i try using those credentials to connect to that db on a c# app , i get the error : unable to retrieve the list of database.
I don't have the right to access the server. I have a user who has rights to two db which i can see when i remotely connect to that server's phpmyadmin. Is it possible that i have right to the db just via phpmyadmin but can't access it via app because i don't have the right to do it because mysql is forbidding it ? I also have a raspberry pi handy. is using it as a db server a better alternative than this ?
Since phpMyAdmin runs on a web server, most people install it on the same machine the database is running on and access it remotely through the network. That means their phpMyAdmin is communicating with MySQL locally, often without the connection leaving the server. Your C# application, on the other hand, is a compiled application that would likely run on your client machine, not the server - meaning any connection from the application to the database is occurring through the network (or internet, depending again on your configuration). Since exposing the MySQL port is generally a bad idea, your MySQL may be configured to only listen locally, or you may have a firewall or NAT connection blocking you from even reaching the server. If that's the case, you may need to rethink how you'll communicate with the database (oftentimes exposing an API is a better solution than opening port 3306 to the world).
It's also possible you're using two different user accounts. To MySQL, an individual user account consists not only of the username, but also the hostname. You can use a wildcard hostname (%) which means all hosts, except it's really "all hosts connecting via TCP/IP networking connection."
It's possible that your application and your phpMyAdmin are using two different connection methods; one using TCP/IP and the other using sockets. Check which phpMyAdmin is using (the easiest way to do so is to look at the host phpMyAdmin is connecting to; 'localhost' is a socket connection and '127.0.0.1' is networking). Configure your C# application the same way.
how to connect two laptops to share a database using windows form application? i mean i've installed mssql server 2008 in my laptop, i need to make windows form application so my friend can modify the database from his laptop, it's not in LAN , we have to use Internet as medium to connect, it'd be helpful if anyone can show me some directions like how connection strings should be. thanks :)
You should consider looking into this. If you search for Error 40 or Error 26 SQL Server. You will get lot of links for connecting SQL Server remotely both on LAN and WAN.
Take a look at this link as well. Screenshots are added here
There are multiple steps involved
Enable default login (sa) - not a good practice
Enable remote connection on sql server
Enable SqlBrowser service - either through Sql Server configuration manager or type services.msc on Run(Ctrl + R)
Add SqlBrowser.exe to firewall exception
Open TCP port 1433 and add it to firewall
Enable TCP, NamedPipe in Sql Server Configuration manager.
Check your public IP using any site like Seemyip.com
Give this IP to your friend along with sql server instance name
On remote machine - enter IP\ServerName with credentials for sa.
OP you just need a dynamic DNS Record (for free at dyndns.org) and then you can create a port forwarding on your Router/Firewall to your SQL server.
That way your SQL Server will be accessible over the internet. Just update your connection string with the dynamic DNS entry that you registered.
This link would be helpful to set the configuration.The link tells how to manipulate connection string according to scenarios.
Here is your:
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;
My application is throwing error from a client machine of not able to connect to the database. So as a test I use SQL Management Studio 2008 on that same client machine to try and connect to the database and I found out that if I use IP\InstanceName then I can connect but if I use ServerComputerName\InstanceName then I can't connect. I have verified the following:
The server has the same gateway and subnet mask as the client.
I can ping the server using either its IP address or its computer name.
No Firewall on either server or client machine.
Verify Server SQL browser service is running.
Verify Server is set to allow remote connection.
Verify Server TCP/IP is enabled via SQL SErver Configration Manager.
I can connect from a different client machine using ServerComputerName\InstanceName
Both server and client are using static IP setup with no DNS server under IPV4 properties.
Tracert from client to server shows only one hop, that is directly to the server machine IP.
I can remote access the client machine from the server machine or viceversa using host name.
I then go to the server machine and connect using LNKLAB8\Xmark (LNKLAB8 is the host name and Xmark is my instance name) and I connected successfully. However, when I run the command SELECT ##SERVERNAME, the result I got back is LNKLABARIAL8\XMARK
This baffled me, because if I right click on the database properties as per the screenshot below, it shows LNKLAB8/Xmark .. am I going crazy or something weird going on here? after taking at the steps I've taken, do you have any suggestion of how I can get the client machine to connect to the database using the server host name instead of the server IP address?
I've kind of hit the wall on this issue, I'm unsure if I am facing a network related issue or it is a database setting issue.
Edit: When I tried to connect using host name to the server DB I would get the following:
network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Try add servers IP and Name to c:\WINDOWS\system32\drivers\etc\hosts
1) Make sure you've enabled TCP/IP (Configuration manager), and restarted MSSQL
<= it sounds like you've done this.
2) Make sure you can "ping" by hostname and by IP
<= It sounds like you've done this, too
3) Make sure MSSQL Browser is running
4) If you're using Windows authentication (vs. SQL Mixed), then make sure you can authenticate to the remote server:
net use \\remote-server /user:<name> <password>
5) Failing all else, you might want to consider reinstalling MSSQL-related components on either/both client or server (for example, MDAC)
Links:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/4d2ce34a-508f-4a1d-8828-8806ccc12f77/sql-server-2005-cant-connect-remotely-using-host-name?forum=sqlsetupandupgrade
http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
https://serverfault.com/questions/384700/error-connection-to-sql-server-using-hostname-instance-or-fqdn-instance-ip
'Hope that helps!
I noticed this:
8: Both server and client are using static IP setup with no DNS server under IPV4 properties.
How is name resolution happening, then? WINS? NetBIOS? Sql Server may not like that. Try checking that you have a working DNS server with the appropriate entry for your Sql Server system, and things may work better.
i have a web site and in it's phpmyadmin create a database and i want to connect to it from c#.
i use MySQL connector for .NET in visual studio 2010.
my String Connection is :
server=158.58.185.197;database=porbarco_base;uid=****;pwd=****;CharSet=utf8;
but i can't connect to database and give an error : Unable to connect to any of the specified MySQL hosts.
How i can connect to this database.
i see many threads in stackoverflow but don't solve my problem.
The likelyhood is that the problem is less your C# and more remote access to MySQL
You need to check the following.
Is MySQL listening a network address. Check your mysql configuration file. Look for an entry for bind address. if its set to 127.0.0.1 then you are just listening on localhost, change it to 0.0.0.0 and remember to restart the service
Is your linux firewall blocking remote access to the mysql port.
Does your mysql allow remote access for the specified user from a remote host. see This link for an example of how to set this up
If you are trying to access it directly using the IP address then the port 3306 needs to be open. Is the port open? If the application is hosted on the same server as the database then I would recommend using localhost to access it instead of the IP address.
I am working on an C# application which would use the remote MySQL database located in my website hosted on a Linux server with PHP & MySQL support.
I tried to connect directly to the MySQL database, but was not able to connect due to restrictions at my hoster side.
can somebody help me please, can i do that with this restrictions ?
You need access to port 3306 on the remote machine. You can test if you have access to this port using telnet or similar
telnet ip 3306
These are the solutions you have:
A) Create local dev environment: You don't provide much information. If my guess is correct you are developing locally and later you plan to deploy your c# application to web server, that also will contain mysql db.
Install mysql in your local machine
Get a copy of the DB.
Configure your C# program to connect to your local mysql (localhost:3306)
When you deploy code it to your web server, it will connect also to your "localhost 3306" that will be the mysql installed into the web server.
B) Use VPN to access mysql: If A is not applicable another solution consist in installing some kind of VPN between web server containing mySQL and the pc running your application. Once VPN is setup and you can access port 3306 (by telnet as explained before), then your app will work.
C) Open ports to access mysql: The most easy solution is asking for administrator to open ports for you. 99% of the times the answer will be no, so I will not follow this route. (Maybe there is some kind of solution in your web provider that allows to open specific ports for a given IP, but I doubt it)
You can't. The server needs to have allowed remote connections and if this isn't possible, than you're out of your luck.
But, there may be another way... If you can create a web service on the server you're able to connect from, you should be able to communicate with the data in mysql virtually from anywhere.
You can try to create a way of API, if your server blocks incoming connections from web, just overload MySQL Functions you need to use with PHP and "echo" results as a server, parse them as a client with your c# application, it is the only way to organize such a system, or, you can allow incoming connection to MySQL, then watch on this article on CodeProject