tags:

views:

95

answers:

2

Hi all i seem to be having an issue with LINQ, i am currently maintaining an in house Intranet application at work,When Saving logs it seems to slow down now,upon debugging i have came to realise that every time it saves a log the application pauses at these two section lines of codes.It does save the logs ,just that its slow and at times super slow.

DataClassesDataContext dab = new DataClassesDataContext();
dab.SubmitChanges();

My question primarily is ,are there any known issues with those two paticuler lines of code giving any sort of problem that can slow down an application? below is the full code used for inserting ,those who understand better could perhaps analyse it better and perhaps correct me where im wrong.Thanks in advance...

DataClassesDataContext dab = new DataClassesDataContext();

newlog = new calllog();
newlog.shortdesc = txtshortdesc.Text;
calllog_description.Text ="*****" + Page.User.Identity.Name + " " + DateTime.Now.ToString()
                       + " ***** " + "\r\n" + calllog_description.Text;
newlog.calllog_description = calllog_description.Text;
newlog.calllog_id = Convert.ToInt32(txtlogid.Text);
newlog.calllogrefno = calllogrefno.Text;
newlog.pr_id = Convert.ToInt32(pr_id.SelectedItem.Value);
newlog.st_id = Convert.ToInt32(st_id.SelectedValue);
newlog.product_id = Convert.ToInt32(product_id.SelectedValue);
newlog.dep_id = Convert.ToInt32(dep_id.SelectedValue);
newlog.log_assigneduser = Convert.ToInt32(log_assigneduser.SelectedValue);
newlog.client_id = Convert.ToInt32(DropDownList1.SelectedValue);
newlog.log_datetime = System.DateTime.Now;
newlog.log_user_id = this.Page.User.Identity.Name;
newlog.calllog_internal = calllog_internal.Checked;
newlog.notify_client = true;
newlog.notify_practise = true;
newlog.ct_id = Convert.ToInt32(ct_id.SelectedValue);
newlog.resolved = false;
dab.calllogs.InsertOnSubmit(newlog);

dab.SubmitChanges();
A: 

Please tell me you don't create data context each time you insert a record into a database?

Minor other issues (maybe's):

  • there a lot of tables set as dependencies in LINQ
  • triggers are slowing you down
  • there a lot indices set
  • problem with database locking
macias
Thanks for the response,please note that i am very new to LINQ,only came across it two weeks ago when i started working on this project.Could you please give in detail what the consequenes are for creating a data context each time a record is inserted, and also this statement "there are lot of tables set as dependencies in LINQ"
Sbee
Okay, I'll operate the two-by-four: it gets slow.
Hans Passant
Sbee, it connects to the DB each time, it is very time consuming (simply set it once and then only use it). If you don't know what is dependency table in LINQ you didn't set it up for sure, so don't worry (in short, LINQ is able to use foreign key info to operate on "linked" table at the same time with the "main" table).
macias
Actually i didnt, the developer who set it up left a couple of months ago in essence i am working through his code and to highlight what you just said(connecting to the DB) i did notice that on the same insert procedure there is another context being opened,and needless to say it also paused there when i debugged so i am going to set it once and see what happens.Thanks....
Sbee
A: 

Another thing to mention is that you should dispose the data context:

using (DataClassesDataContext dab = new DataClassesDataContext())
{
    dab.calllogs.InsertOnSubmit(newlog);
    dab.SubmitChanges();
}
Nappy