we have many databases(every server one database) with same structure
if i wanna connect to fist server with my code (c# .net 6) its will be connect but when wanna connect to other server cant connect to them. i test ping cmd for other server to test the connection and the server will be response well i dont know what to do . any help ?
heres my code :
using (var con = new MySqlConnection("Server = *****.105; Database = asterisk; Uid = asterisk; Pwd = *******; port=3306;"))
{
try
{
con.Open();
con.Close();
}
catch
{
Console.WriteLine("false");
}
}
i tried with name and ip,port and test with mysql.data.mysqlclient and mysql.connector library but it doest work !!!!!
heres my exeption :
SocketException: 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.
and
IOException: Unable to read data from the transport connection: 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..
Use the "SqlConnectionStringBuilder" object to connect to mysql.SqlConnectionStringBuilder can be used to help generate connection strings.
// Information about connecting to the database
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
//username
builder.UserID = "root";
//password
builder.Password = "root";
//server address
builder.Server = "localhost";
//database when connecting
builder.Database = "***";
//Define the link to the data connection
MySqlConnection connection = new MySqlConnection(builder.ConnectionString);
// open this link
connection.Open();
Redownload mysql:
mysql connection code:
//Define mysql connection string
string constring = "data source=localhost;database=test1;user id=root;password=root;pooling=true;charset=utf8;";
//connect to mysql
MySqlConnection msc = new MySqlConnection(constring);
msc.open();
Hope it helps you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.