Reputation: 15
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();
Upvotes: 0
Views: 1227
Reputation:
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
Upvotes: 1
Reputation: 366
better try with Entity Frame work
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" />
Add follow codes in your code
private MySqlConnection con; con = new MySqlConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings["UserContext"].ConnectionString; con.Open();
Upvotes: 0