ASP.NET use SqlConnection connect MySQL

前端 未结 3 432
既然无缘
既然无缘 2020-11-27 21:16

This is the connection string saved in web.config:


    

        
相关标签:
3条回答
  • 2020-11-27 21:38

    SqlConnection is for SQL Server. You need MySqlConnection - this is not part of the .NET Framework, so you will have to download it and reference it in your project. You can then create a MySqlConnection object and connect to MySQL in your application:

    MySqlConnection connection = new MySqlConnection(myConnString);
    

    You will also have to use the MySqlCommand object rather than the SqlCommand object.

    http://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqlconnection.html

    0 讨论(0)
  • 2020-11-27 21:38

    as Darren seid "SqlConnection is for SQL Server." you need to install MySql.Data from NuGet: mySql.Data

    also you can use Install-Package MySql.Data in your Package Manager Console

    then you can create MySqlConnection object and connect to your database:

    var cnn = new MySqlConnection("my Connection String");
    
    0 讨论(0)
  • 2020-11-27 22:05

    Not that I know of, and even if it would, why would you want to? You are using a connection object specifically created for Microsoft SQL Server, so it wouldn't connect in the same fashion MySQL does.

    For accessing a MySQL database, you should use the MySQL .NET connector which you can find here.

    0 讨论(0)
提交回复
热议问题