1.Access denied for user ' root ' @ ' Desktop-an72kei ' (using Password:yes)
This problem occurs because MySQL's own user root is theoretically not allowed to access, only local access, if you need to access the user, you need to modify some of the MySQL configuration files, it is best to use their own new users and give administrator privileges.
2.No Database selected
The reason for this error is that the database does not find the corresponding data, here it is necessary to make a decision whether or not null. , and it is important to note that the database needs to be specified in the connection string, or the error may occur.
3. Parameterization of statements
The demo is as follows:
stringconn ="server=192.168.60.128;database=mysql_test; User id=sqladmin;password=123"; using(Mysqlconnection Mconn =Newmysqlconnection (conn)) {Mconn. Open (); //String sql = "Select T.sname from student t WHERE t.sid =2"; stringsql ="SELECT t.sname from student t WHERE t.sid =?id"; Mysqlcommand Mcomm=Newmysqlcommand (SQL, mconn); Mcomm. Parameters.Add ("ID", Mysqldbtype.int32); Mcomm. parameters["ID"]. Value =2; varres =Mcomm. ExecuteScalar (); if(res = =NULL) { return NULL; } Else { returnRes; } }
4. The space to be introduced:
Using System.Data;
Using Mysql.data;
Using MySql.Data.MySqlClient;
5. Required DLLs:
6.Unable to connect to any of the specified MySQL Hosts. This error occurs because the wrong port number is specified or the address of the server is incorrectly written, and the port number is not specified as the default is 3306 also please God pointed out that I experimented with the connection to the virtual machine when there is no specified port number and no error, the complete link statement:
Server=192.168.60.128;port=3306;database=mysql_test; User id=sqladmin;password=123, you can specify properties in the configuration file:
Providername= "MySql.Data.MySqlClient"
C # link MySQL Novice error-prone issues