I have a windows forms project that connects to a sql server using ef core. I have different controls on my form that are data bound through bindingsource objects. But I have to fill a datagridview using a stored procedure that provides different number of columns, so I can not map the stored procedure or its result to a data entity. Instead I use a Datatable object as a datasource for the datagridview. This works all fine as long as I connect to a local sql server. But when I use a remote sql server through a vpn connection I can fill the datagridview only once before it freezes while the other controls continue working.
Here is some code:
//binding a textbox
private List<someentity> _somedatalist;
private BindingSource _someBS= new BindingSource();
_somedatalist=null;
_somedatalist= new List<someentity>(await GetData());
sometextbox.DataBindings.Clear();
_someBS.DataSource = null;
_someBS.DataSource = _somedatalist;
//filling datagridview
DataTable dt = new DataTable();
SqlConnection myConn = new SqlConnection(GetConnString());
myConn.Open();
SqlCommand myCmd = new SqlCommand("MyStoredProc", myConn);
myCmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(myCmd);
da.Fill(dt);
datagridview1.DataSource = dt;I suppose it has something to do with synchronicity but I don't know how to improve my code.
Any idea?