[英]mysql connection failed with c#
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.如果我想用我的代码(c#.net 6)连接到第一个服务器,它会连接但是当想连接到其他服务器时无法连接到它们。 i test ping cmd for other server to test the connection and the server will be response well i dont know what to do .
我为其他服务器测试 ping cmd 以测试连接,服务器将响应良好,我不知道该怎么做。 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 !!!!!我尝试使用名称和 ip、端口并使用 mysql.data.mysqlclient 和 mysql.connector 库进行测试,但它不起作用!!!!!!
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. SocketException:连接尝试失败,因为连接的一方在一段时间后没有正确响应,或者连接的主机没有响应,建立连接失败。
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.. IOException: Unable to read data from the transport connection: 连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机没有响应..
Use the "SqlConnectionStringBuilder" object to connect to mysql.SqlConnectionStringBuilder can be used to help generate connection strings.使用“SqlConnectionStringBuilder”对象连接mysql。SqlConnectionStringBuilder 可用于帮助生成连接字符串。
// 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:
mysql connection code: mysql连接代码:
//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.希望它可以帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.