0
myConnection = new SqlConnection("user id=champion3_test;" +
                                       "password=test;server=10.168.1.58;" +
                                       "Trusted_Connection=true;" +
                                       "database=champion3_sabdb; " +
                                       "connection timeout=30");

此代码给出了错误:

Thrown: "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.SqlException) Exception Message = "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)", Exception Type = "System.Data.SqlClient.SqlException", Exception WinRT Data = ""    

以下是一些可能有助于调试我的服务器设置的屏幕截图:http: //imgur.com/a/PeRby

我知道'champion3_test'是一个有效的用户ID'test'是champion3_test的有效密码数据库名称是'champion3_sabdb'

4

2 回答 2

4

SQL 服务器不是 MySQL。如果您使用的是 MySQL,请下载 MySQL .NET 连接器并使用它们的连接类MySqlConnection

要了解如何使用 MySQL 连接器,您可以从这里开始。

于 2013-03-13T15:06:24.683 回答
0

您可以在此处下载适用于 .Net 的 MySql 连接器。

安装驱动程序后,您可以使用 MySql 连接器类进行连接:

 string connStr = "server=localhost;user=root;database=world;port=3306;password=******;";
 MySqlConnection conn = new MySqlConnection(connStr);
于 2013-03-13T15:09:59.703 回答