gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 21:10:21 25 4
gpt4 key购买 nike

我正在尝试将一些代码从 JavaFX 迁移到使用 C# for Windows Forms。在 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]";

最佳答案

下面是 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。

关于java - 无法连接到 .NET 中的远程 MySQL (MariaDB) 数据库,但可以使用 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58906707/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com