R.D Ip

R.D Ip

  • 2k
  • 74
  • 1.4k

internal connection fatal error in c#

Apr 27 2021 4:35 AM
I am using thread because when open a form the fill the background data in combobox and store procedure combobox data successfully but issue is when I open a form and immediately I press the close button then give an
error like:
 
internal connection fatal error
connection close
 
I am trying but not able to solve this error
 
please help
 
myform.cs
  1. public void ShowForm()      
  2. {      
  3.    this.Show();            //here open a form      
  4.    WorkerSetControl(() => Load_Datas());   //call a thread       
  5. }  
Thread ObjThreads;
  1. private void WorkerSetControl(Action methodName)      
  2. {      
  3.     ObjThreads = new Thread(new ThreadStart(() => methodName()));      
  4.     //ObjThread.IsBackground = true;      
  5.     //ObjThread.SetApartmentState(ApartmentState.STA);      
  6.     ObjThreads.Start();      
  7.       
  8.     //if (!ObjThread.Join(TimeSpan.FromSeconds(30)))      
  9.     //{      
  10.     //    ObjThread.Abort();      
  11.     //    throw new Exception("More than 30 secs.");      
  12.     //}      
  13. }      
  14.       
  15. public void Load_Datas()      
  16. {      
  17.     _product.FillForCombo(_prdcode, _prdtype, UltCmbprdType.Text);      
  18.             
  19.     _product.SetColumn(_PrdMast.TableNameProductList, "CODE,DESC,RG""90,100,200");      
  20.     _product._SetDataBinding(_ProdDS,  TableNameProductList, true);      
  21. }      
  22.       
  23. protected override void OnFormClosing(FormClosingEventArgs e)   //Here I am closing a form    
  24. {      
  25.     this.Enabled = false;   // or this.Hide()      
  26.     //ObjThreads.IsBackground = false;      
  27.     //Thread.Sleep(1);      
  28.     //_product.ds = null;      
  29.     this.Hide();      
  30. }  
_Prod.cs
  1. public DataSet DS    
  2. {    
  3.     get { return _DS; }    
  4.     set { _DS = value; }    
  5. }    
  6.     
  7. public void FillForCombo(string pStrCompCode, string pMast_Type, string pStsOrdType = "")    
  8. {    
  9.     Ope.Clear();    
  10.                 
  11.     Ope.AddParams("Cmp_Code", pStrCompCode);    
  12.     Ope.AddParams("M_Type", pMast_Type);    
  13.     Ope.AddParams("P_TYPE", pStsOrdType);    
  14.     
  15.     //if(ConnectionState.Open != ConnectionState.Closed)    
  16.     //{    
  17.     //if (Ope.IsConnectionCheck(Ope.EnumServer.servername) == true)    
  18.     //Ope.OpenConnection(Ope.EnumServer.servername);    
  19.     Ope.FillDataSet(Ope.EnumServer.servername, DS, TableNameProductList, Spp.usp_PrdsFillForCombo, Ope.GetParams());       
  20.     //here give an error internal connection fatal error / connection closed error when open a form and immidiately i close a form then give an error  
  21. }  
OperationSql
  1. namespace DataLib    
  2. {    
  3.     public class OperationSql : GlobalSql    
  4.     {    
  5.         public static CultureInfo CultureInfoUS;    
  6.         public static Hashtable HTParam;    
  7.         public static int IntParamCount;    
  8.     
  9.         public OperationSql();    
  10.             
  11.         public static void CCon(EnumServer ServerCon);    
  12.         public static void CCon(SqlConnection pConn);    
  13.         public static void Clear();    
  14.         public static void CloseConnection(EnumServer ServerCon);    
  15.         public static void ClsRed(SqlDataReader pReader);    
  16.         public static bool OpenConnection(EnumServer ServerCon);    
  17.         public static void FillDataSet(EnumServer ServerConn, DataSet pDataSet, string pTableName, string pProcedureName, SqlParameter[] pParamList, bool pSetTime = falsebool pBlnCatch = true);    
  18.     
  19.         public enum EnumServer    
  20.         {    
  21.             servername = 1,    
  22.             servernamesd = 2    
  23.         }  
  24. }  
when i open a form and after sometime I press close button then not give an error but when I open a form and suddenly press a button then give an error
 
internal connection fatal error / connection close error / object referance not set to an object
 
I know why give an error because thread running in background and I press the close button quickly when open a form that is problem
 
please help

Answers (8)