C # link MySQL Novice error-prone issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.