What is the best way to connect remotely to MySQL server on domain ?
I want to make an desktop app or maybe it is easier to do it with asp.net ?
Use Mysql Workbench for desktop use to connect to Mysql Server.
For coding: Get Mysql client library for .net . It's called mysql connector. Add
using Mysql.Data; namespace
https://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting-open.html
Makes no difference what kind of application you are creating.
your code will look very similar like this one:
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString = "server=127.0.0.1;uid=root;" +
"pwd=12345;database=test;";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);
conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}
1- I usually use HeidiSQL tool to connect to MYSQL server otherwise on localhost or remotely servers on CPanels.
most of CPanels allow to remote connection by adding % at access hosts field to enable me connect remotely anywhere.
from your cpanel go to the database tools then -> you will find link for Remote mysql -> then you can any IP address to make server allow to connect, if you want connect anywhere you put %.
Note: CPanels are little different each others.
2- if you want connect to mysql in your code, you make a normal connection after doing step 1.
Related
I've been trying the following code to attempt to connect to a remote database I'm hosting on digital ocean.
MySqlConnection myConnection = new MySqlConnection("Server = 104.236.197.146; Port = 3306; Database = BattleRoyale; Uid = root; Pwd = password");
try
{
myConnection.Open();
}
catch (Exception e)
{
MessageBox.Show( e.ToString(), "Database connection error" , MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Whenever I attemt to run this code I get the following error:
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySql hosts.
I believe the problem is with the hosted database. I've tried the following things:
GRANT ALL PRIVILEGES ON . TO root#"%" IDENTIFIED BY 'rootPass';
I've been trying to check to see if TCP/IP is enabled, but I cannot find it via phpMyAdmin nor going through putty or anything.
As you can tell, I don't know much about Linux machines and I'm just trying to connect to this database to work on a school project. Who knows what I've done trying to fix this issue. Any help would be greatly appreciated.
Possible reasons include:
MySQL is configured to listen on "localhost" or 127.0.0.1 only - this does not allow remote connections at all, regardless of the firewall configuration
Firewall may be configured to not let through communication on port 3306
MySQL may not be running on the standard port 3306 but some other port
Most probably it's 1. or 2. Especially 1. is something you don't think of at first.
Please note that many hosters don't allow access to the databases from outside their own network. That's why often PhpMySQL works but remote connections don't.
I have a windows form application in C# and sometimes I want to push some data table from this application to an online mySql server which is hosting all data for my website in PHP. To do that I've installed :
1- MySql for visual studio version 1.2.3
2- MySql Connector.Net 6.9
Also, I have enabled Remote MySql on the server so I can make the connection. I used the '%' wildcard for the meantime because my IP address is dynamic.
my basic c# connection code is as below :
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString = "Server=*******;Database=*******;Uid=******;Pwd=********;";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
MessageBox.Show("connected successfully..");
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}
Unfortunately, every time I run this code I am getting an error which says
"Unable to connect to any of the specified MySQL hosts".
I don't' know where the problem is. Is it something on the UNIX server which
blocks the connections or some other thing which I need to do. I am also new to the CPanel interface and how to deal with it.
I appreciate all the help provided.
Many Thanks.
http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL
Did you see that? You can try it.
I know this is an old question but I had the same issue many years ago and the only way I could get it to work was to enable remote MySql on the server I was running. This basically means allowing remote connections to access the DB. This of course is very risky and poses a major security problem. You can limit connections from specific IPs, but in my opinion its best to have a local DB and then perhaps push updates to an online source somehow.
I have installed postgresql database in http://postgres-project-1241043.j.layershift.co.uk/ host.
I want to connect to the database using C#. I use Npgsql with following connection string.
connectionString = # "Server = postgres-project-1241043.j.layershift.co.uk, Port = 5432, User Id = postgre; Password = abcdef; Database = dbluanvantn;";
But I am not able to connect to the server and get error:
Npgsql.NpgsqlException: Failed to a connection to
'postgres-project1241043.j.layershift.co.uk'.
Am I using correct connection string?. Help me fix it.
You can only connect to Postgres (on our Jelastic service) if you add a public IP to the node first. Without that step, you can only connect to it locally (i.e. from another server within your Jelastic environment).
Also I want to mention that you are always welcome to contact our support team (our tech. support is 24x7 and completely free; even for our trial accounts) if you need any further help.
I need to connect my C# application developed in my Standalone PC with my Hosted Linuux MySQL Server. How can i do it.. Is there any server configuration setup or any kind of Remote Connection Permission Setting have to be done? Please help with this..
Make sure that the server where MySQL is at can accept connections.
Read this to read how to configure your c# application to connect to MySQL.
The connection string code should like this
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
You need to allow the remote connection by this way
Mysql has very good documentation how to connect mysql server (local and remote).
It is here http://dev.mysql.com/doc/index-connectors.html
And your case may be this http://dev.mysql.com/doc/connector-c/en/index.html
Its Pretty Simple to Implement
1) Download My Sql Connector From https://dev.mysql.com/downloads/connector/net/6.9.html
2) In your C# Project add refrence of Mysql.Data.Dll
3) use this Connection String
string connectionString= "SERVER=000.000.000.000;DATABASE=testdb;UID=test;PASSWORD=test123;"
4) use same like this sample code
MySqlConnection conn = new MySqlConnection(connectionString);
try
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();
// Perform database operations
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
conn.Close();
Console.WriteLine("Done.");
or Read this tutorials
https://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-connection.html
I'm building a c# windows application which will connect with the mysql database in a remote server.
I'm using the following connect script
string connectionString;
connectionString = "SERVER = eu5.org;UID = myuserid; PASSWORD = mypassword; DATABASE = mydatabasename;";
connection = new MySqlConnection(connectionString);
It shows the error couldn't connect to the database.
P.S: Mysql database is at eu5.org server
Personally I prefer to use the MySql Workbench IDE for testing connections and working (Querying) the database directly where possible. Most hosted databases that I have worked with normally define the Server as Instance.[DomainName] so I would have expected your server URL to be something like MySql1.eu5.org
Below is a connection string that I tested using the MySql Connector, change the parameters.
<connectionStrings>
<add name="MySqlConnection" connectionString="server=INSTANCENAME.DOMAINNAME.COM;UID=USERNAME;password=PASSWORD;database=DATABASENAME;Persist Security Info=True;" providerName="MySql.Data.MySqlClient"/>
MAke sure that your server should be started...
Just read the FAQ:
Many people want to only use database, but their site is hosted elsewhere. We provide free database for websites hosted with us. For that reason, external access is blocked without exception.
--> http://www.freewebhostingarea.com/faq.html
so it's not possible to access your MySQL-DB from external sources.
only localhost will be allowed
Your code is correct.
Use a browser for MySQL, like http://mysql-query-browser-for-windows.apponic.com/ to check if your database is available.