简体   繁体   中英

Can't access MYSQL server from c# forms application - error in connection string

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

This code gives the error:

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 = ""    

Here are some screenshots that might help with debugging of my server's settings: http://imgur.com/a/PeRby

I know that 'champion3_test' is a valid user id 'test' is a valid password for champion3_test the database name is 'champion3_sabdb'

SQL server isn't MySQL. If you are using MySQL, download the MySQL .NET Connector and use their connection class, MySqlConnection .

To learn how to use the MySQL Connector, you can start here .

You can download the MySql Connector for .Net here .

Once you've installed the driver, you can connect using the MySql Connector classes:

 string connStr = "server=localhost;user=root;database=world;port=3306;password=******;";
 MySqlConnection conn = new MySqlConnection(connStr);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM