【问题标题】:Can't connect to remote MySQL (MariaDB) database in .NET but I can with Java无法连接到 .NET 中的远程 MySQL (MariaDB) 数据库,但我可以使用 Java
【发布时间】:2020-03-13 08:36:54
【问题描述】:

我正在尝试从 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]";

【问题讨论】:

标签: java c# mysql winforms mariadb


【解决方案1】:

这里是一个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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-10
    • 1970-01-01
    相关资源
    最近更新 更多