无法连接到.NET中的远程MySQL(MariaDB)数据库,但可以使用Java

时间:2019-11-18 00:55:21

标签: java c# mysql winforms mariadb

我正在尝试从JavaFX迁移一些代码以将C#用于Windows窗体。在Java中,我使用的是JDBC,并且可以通过编程很好地进行连接。否,我正在尝试使用C#,但出现此错误:

A 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server).

我使用相同的服务器地址和凭据。我正在使用System.Data.SqlClient。我尝试了很多不同的组合,但无法使用连接字符串。

String connectionString = "server=[Server URL];database=[Database Name];persist security info=true;user id=[Username];pwd=[Password]";

1 个答案:

答案 0 :(得分:0)

以下是mysql连接字符串的示例:

string connectionString = "datasource= <database ip or domain>; port=<port, usually 3306>;username=<database user>;password=<user's password>;SslMode=none<this is important if you don't use ssl>;database=<your database>";

我认为您无法连接的原因是因为您尚未指定SslMode。