0

I have an error while connecting my project into mysql database so i have added the code bellow to my button to fetch all rows and display it in a gridView

protected void Button1_Click(object sender, EventArgs e)
        {
            MySqlConnection myconn = new MySqlConnection("server=localhost;uid=root;password=;database=y;");
            string strSQL = "select * from welcome";
            myconn.Open();
            MySqlDataAdapter mydata = new MySqlDataAdapter(strSQL, myconn);
            MySqlCommandBuilder cBuilder = new MySqlCommandBuilder(mydata);
            System.Data.DataSet ds = new System.Data.DataSet();
            mydata.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
            myconn.Close();
        }

When running the the app it shows an error in myconn.Open();

An exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll but was not handled in user code

Additional information: The host localhost does not support SSL connections.

and it pointed to myconn.Open();

3
  • no answer i need to solve this error urgently Commented Jun 23, 2018 at 15:02
  • You probably have an error either in your connection string or in your select statement. Verify that "welcome" is a table in your mysql database (check for case sensitivity). Also make sure that your database name and password are correct. Commented Jun 23, 2018 at 15:49
  • my database username and password is correct Commented Jun 23, 2018 at 15:53

2 Answers 2

1

change myconn to :

MySqlConnection myconn = new MySqlConnection("server=localhost;uid=root;password=;database=y;sslmode=none");

Make sure that you are adding sslmode=none in myconn

Sign up to request clarification or add additional context in comments.

Comments

0

better try with Entity Frame work

  1. Add ADO.NET Entity model,If will ask to connect db and give some name(ex :userentities)
  2. Then, use below code in your coding

userentities context = new userentities();

 protected void Button1_Click(object sender, EventArgs e)
        {
            using (var dbTransactionContext = context.Database.BeginTransaction())
            {
                //then do the operation
            }
        }

It's really easy

or other wise follow these steps 1. add your connection string in web config

 <add name="UserContext" connectionString="server=localhost;User Id=root;password='';database=databasename;convert zero datetime=True" providerName="MySql.Data.MySqlClient" />
  1. Add follow codes in your code

    private MySqlConnection con; con = new MySqlConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings["UserContext"].ConnectionString; con.Open();

5 Comments

connectionString="server=localhost;User Id=root;password='';database=y;convert zero datetime=True" providerName="MySql.Data.MySqlClient"
change your connection string as above and give a try
I Didn't touched my code , I just added the above code in my webConfig and click run it shows this error(HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory. Most likely causes: A default document is not configured for the requested URL, and directory browsing is not enabled on the server.)
I modified the code and i got same errors as on my Post
i got this error {"The host localhost does not support SSL connections."}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.