keyur gajjar
keyur gajjar

Reputation: 1

The given key was not present in the dictionary. In plesk server

I am facing "The given key was not present in the dictionary" error while binding the repeater to the data adapter's fill() method and inserting data into the database while opening a database connection.

This issue occurs only on the Plesk server (Web Hosting) and not on the local server.

connectionString="data source=103.21.58.4;port=3306;initial catalog=lokhandwala;user id=lokhandwalauser; password=Lokhandwala@359#;CharSet=utf8;"

asp.net Framework="4.8.0"

MySQL version="8.0.10.0"

Stack Trace:


[KeyNotFoundException: The given key was not present in the dictionary.]
   System.ThrowHelper.ThrowKeyNotFoundException() +38
   System.Collections.Generic.Dictionary`2.get_Item(TKey key) +54
   MySql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion version, String CharSetName) +53
   MySql.Data.MySqlClient.CharSetMap.GetEncoding(DBVersion version, String CharSetName) +54
   MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection) +975
   MySql.Data.MySqlClient.NativeDriver.Configure(MySqlConnection conn) +16
   MySql.Data.MySqlClient.MySqlConnection.Open() +474
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +182
   System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +465
   System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +147
   _Default.Page_Load(Object sender, EventArgs e) in d:\inetpub\vhosts\business7days.net\lokhandwalageneralhospital.business7days.net\Default.aspx.cs:26
   System.Web.UI.Control.OnLoad(EventArgs e) +108
   System.Web.UI.Control.LoadRecursive() +90
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1533

Repeater binding code:

  public string errmsg;
    protected void Page_Load(object sender, EventArgs e)
    {
        using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["default"].ConnectionString))
        {
            con.Open();
            MySqlCommand cmd = new MySqlCommand("select * from services", con);

            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            DataTable dt = new DataTable();

            da.Fill(dt); //The error* triggered here

            if (dt.Rows.Count > 0)
            {
                rptLink.DataSource = dt;
                rptLink.DataBind();
            }
            else
            {
                errmsg = "dtnull";
            }
            
            cmd.Dispose();
            con.Close();         
        }
    }

Data insert code (Click event of submit button):

 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            if (!Validator())
            {
                string strname1 = fu.FileName.ToString();
                fu.PostedFile.SaveAs(Server.MapPath("~/upload/") + strname1);


               con.Open();//The error* triggered here
 
                using (MySqlCommand cmd = new MySqlCommand("insert into aboutus (`title`, `headline`, `sdes`, `des`, `img`, `pagetitle`) values (@1,@2,@3,@4,@5,@6)", con))
                {
                    cmd.Parameters.Add("@1", MySqlDbType.VarChar).Value = txtTitle.Text;
                    cmd.Parameters.Add("@2", MySqlDbType.VarChar).Value = txtHeadLine.Text;
                    cmd.Parameters.Add("@3", MySqlDbType.VarChar).Value = txtsDes.Text;
                    cmd.Parameters.Add("@4", MySqlDbType.VarChar).Value = ckDesciption.Text;
                    cmd.Parameters.Add("@5", MySqlDbType.VarChar).Value = strname1;
                    cmd.Parameters.Add("@6", MySqlDbType.VarChar).Value = txtPagetitle.Text;

                    cmd.ExecuteNonQuery();
                }
                con.Close();
                Clear();
                sucmsg.Visible = true;
                lblsuc.Text = "Successfully Added:)";
                //BindGrid();
            }
        }
        catch
        {
            
        }
    }

I tried all combinations of solutions like check if data is getting or not. The data is getting correctly in the local server, but in the Plesk server, I don't know why the error is coming.

Upvotes: -1

Views: 29

Answers (0)

Related Questions