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