I am going to make a smaill application with c# .net 2.0 here I have to connect the Mysql server i am trying many tutorial but fail
I am using
string constr = "Server=11.22.33.123;Port=3306;Database=bfcerin_ad;" +
"Uid=<user id here>;Pwd=<password here>;pooling=false;";
MySqlConnection con = new MySqlConnection(constr);
con.Open();
I have tried twice my user name and password is fine but getting access denied from Server
I am able to connect to the localhost mysql with this code but not remote mysql server
Login your cpanel and click on Remote MYSQL and then add Remote Database Access Hosts put % for giving access to all host.
Related
I have already implement a control panel for MySQL database. That works perfect with local database which is installed on my PC. But when i try to connecting with mysql database on my web host i get this message:
cannot connect to any of the specified mysql hosts
Here is my connection string:
var csb = new MySqlConnectionStringBuilder
{
Server = "database.webhost.com",
Port= "3306"
UserID = "root",
Password ="1234567",
Database ="sampleDB",
SslMode= "None",
};
I was reading something about SSH secure connections to web hosts, but i can't find any examples.
I've built a C#-application and now I want to connect that application with an MySQL-Server that is running in my local network.
For this purpose I used the MySQL-connector like the following:
string connectionString = "server=192.168.0.11;uid=User1;pwd=PWD1234;database=Caller;";
MySqlConnection conn = new MySqlConnection(connectionString);
conn.Open();
But everytime I want to connect to the database and open the connection, it fails with the error "Unable to connect to any of the specified MySQL hosts.".
I've tried a couple of different things:
Granted all privileges on the user
GRANT ALL PRIVILEGES ON . TO 'User1'#'%' IDENTIFIED BY 'PWD1234' WITH GRANT OPTION; FLUSH PRIVILEGES;
Changed the MySQL-configuration file
Now it doesn't contain a line like bind-adress or skip-networking anymore.
Restarted the MySQL server
So where is the problem? I am not able to figure it out...
The server is running on Ubuntu Server, actual version.
Thank you and with best regards,
Nicolas
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.
I want to create connection string so that I can connect to SQL database remotely in my C# code using OleDb as a provider and the server IP address.
Note 1 : I'm using OleDb because I want to handle different database types. SQL is just an example.
Note 2 : The database resides on another machine (machine on another network)
I did all the setup to connect from another machine (firewall,Enable TCP/IP..etc), and now I can connect remotely using Microsoft SQL Server Management 2014 by specifying (server name : My Computer Name-PC\Instance name) and using SQL Authentication then entering the username and password and press connect and then it goes well, I connect successfully.
BUT I TRIED A LOT OF COMBINATIONS TO BUILD THE CONNECTION STRING IN MY C# CODE AND NONE OF THEM WORKS EXCEPT THIS :
OleDbConnection conn = new OleDbConnection(#"provider = sqloledb; data source = MyCompName-PC\sqlexpress; Initial Catalog = DataBase1 ; user id = MyUsername ; password = MyPassword ;");
Otherwise if I try to use my server public IP address instead of MyCompName in Data Source it keeps giving me error : server not found or access denied.
I search in connectionstrings.com but problem is still there.
From your post it looks like you are trying to connect to a SQL Server database then why are you using OleDbConnection? instead of using SQL Server connection provider.
OleDbConnection connection provider is used for connecting to MS Access database.
You should be using a SqlConnection class like
SqlConnection conn = new SqlConnection("data source = MyCompName-PC\sqlexpress; Initial Catalog = DataBase1 ; user id = MyUsername ; password = MyPassword ;")
See SQLConnection Reference for more information as commented by #AlexK.
I want to connect my windows form application to mysql .It works local mysql server perfectly.But it didn't work in online mysql.
My code is
string mysqlconnection = "Server=mysql.main-hosting.com;Database=xxxxxxxxx;Uid=yyyyyyy;Password=zzzzzzzz;";
MySqlConnection connection = new MySqlConnection(mysqlconnection);
connection.Open();
It shows Unable to connect to any of the specified MySQL hosts..How to solve this?
Try
Server=mysql.main-hosting.com;Database=xxxxxxxxx;User ID=yyyyyyy;Password=zzzzzzzz;
Instead of
Server=mysql.main-hosting.com;Database=xxxxxxxxx;Uid=yyyyyyy;Password=zzzzzzzz;
Maybe it is a connectionstring problem.
Or otherwise the server address is wrong.