0

When i enter username and password on my site. if the username and pasword are correct, then i have a c# method called on Page_Load for database (which delete the non-required records). if there is one record or 100, i still have to wait for the page load until that process is completed :( I am using this string to load all the files, which will be then used to compare files HttpContext.Current.Request.PhysicalApplicationPath; how ever if i used a static path i.e : c:/images, then things goes bad :( so what could be the possible solultion ?

Fionnuala
  • 90,370
  • 7
  • 114
  • 152
safi
  • 3,636
  • 8
  • 24
  • 37
  • 1
    maybe if you post some code we can help you optimize it – Kris Ivanov Jan 26 '11 at 14:09
  • It can depend on a lot of things. Is the DB locally hosted? What's the spec of the server? Have you tried optimizing the code? – Prisoner Jan 26 '11 at 14:10
  • @k Ivano, the code is simple just query the Access D.B and check if the file name match delete (simple using OLEDB) – safi Jan 26 '11 at 14:18
  • @ Prisoner: I am using Access DB, currently located on host, No i havnt tried Optimization Code. – safi Jan 26 '11 at 14:20
  • Can you post the code you are using to do the delete? If you have a "NOT IN" for instance it would not be highly performant. – Mark Schultheiss Jan 26 '11 at 15:10
  • Are you deleting by walking a recordset, or by issuing a SQL DELETE command? As others have pointed out below, opening the first connection to a Jet/ACE database is very slow because of the overhead of setting up the record locking file. I would recommend against using Jet/ACE as data store for a web application, as it's simply not designed for that operating environment. – David-W-Fenton Jan 26 '11 at 23:04

3 Answers3

2

You can start the record removal asynchronously:

Then your Page Load will occur before the removal operation is finished.


EDIT: Since you mention that you are using an Access DB, I guess that you are not losing the time by deleting the records but by some other operation (I suspect closing the DB, see my comment to Amir's answer). The thing you should do now is to benchmark, either by using a tool (see this question) or "manually", using the Stopwatch class. Any way, before you try to optimize, use one of these methods to find out what is really causing the delay.

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519
  • @heinzi, thanks i do that now, when i do not use that sql to query the DB then it goes like a flash(as the page has to load (XML,AJAX) and most amazingly the user is verification is done fast. but this thing is like bone..... – safi Jan 26 '11 at 14:35
  • @safi: And if you measure the time exactly, is the time really lost during `myCommand.Execute`? – Heinzi Jan 26 '11 at 14:44
  • @Heinzi: yes the time is consumed when executing the command on DB. when that is Completed, the page load so fast – safi Jan 26 '11 at 14:47
  • @safi: Well, if you are sure about this (and the deleting of the records must be done at this point in time), then asynchronously executing the command sounds indeed like the way to go... – Heinzi Jan 26 '11 at 14:55
  • @ Heinzi, any hints about asynchronously executing the command in ASP.NET/C#? – safi Jan 26 '11 at 14:57
  • @safi: I just realized that these asynchronous operations are only available in SqlCommand, not in OleDbCommand. So, I guess the easiest solution is to create a background thread and run the code there. Running a background thread in ASP.NET is a bit too tricky to explain in a simple comment, but there are lots of resources about that on the web. – Heinzi Jan 26 '11 at 15:07
  • @ Heinzi, thanks i have updated the question, can you read and suggest me now? – safi Jan 26 '11 at 15:09
  • @safi: I'm sorry, but I really don't understand how your update relates to your original question... – Heinzi Jan 26 '11 at 16:12
0

Use Ajax and make it async as a web service.

Edit1: What I mean is to move the code in the Page_Load into a web service method, then call that web service from javascript after the page loads, sending it the information it needs to properly perform your operation, thus the client side appears more responsive - I make the assumption that the actions taken are not required to properly render your client side code, however if not, you might consider updating the page after the web service returns. This could be done manually, through the built in ajax toolkit or via a library such as jQuery.

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
  • you mean to say i should put [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)] b4 the class? – safi Jan 26 '11 at 14:16
  • when i do not use that sql to query the DB then it goes like a flash(as the page has to load (XML,AJAX) and most amazingly the user is verification is done fast. but this thing is like bone. – safi Jan 26 '11 at 14:36
0

This doesn't sound like a async problem to me. Deleting 100 or even 1000 records in a database shouldn't take more than a few milliseconds. If I was to suspect, I would think you have not set up your indexes correctly. So instead of deleting those records using a quick index, it needs to look through every record and see if its a match.

Amir Raminfar
  • 33,777
  • 7
  • 93
  • 123
  • I did the Indexing Now, but it the same problem. – safi Jan 26 '11 at 14:23
  • 2
    Opening and (in particular) closing an Access database takes a horrible amount of time. I was optimizing the load time of a web application recently, and *closing* the connection to an Access DB took a few hundred(!) milliseconds, even though it was only a tiny DB, opened to read a single value of a tiny table. Caching this value made the Page_Load time drop in orders of magnitude. – Heinzi Jan 26 '11 at 14:26
  • Hmm something doesn't sound right. Try adding 1000 records and then deleting it from the database without using C#. Does it still take a long time. I am not an expert in Access. – Amir Raminfar Jan 26 '11 at 14:27
  • @Heinzi - that's what connection pooling is good for. The application should not open connections to the db. They should already be there available. – Amir Raminfar Jan 26 '11 at 14:28
  • @ the actual problem is that the process exceute parallele with the page_loading, the page_load has to load other resources like xml and other stuff, and this process make it slow, so is there any way to send this process in the background without the itnerreuption of the page_load items/speed? – safi Jan 26 '11 at 14:32
  • How slow are we talking about?? – Amir Raminfar Jan 26 '11 at 14:34
  • suppose without this call to DB it goes so fast, but a call to DB then page is hanged with a hangover/awaiting mouse ICON – safi Jan 26 '11 at 14:37
  • I am not an expert in .Net so I don't know. But this can't be right. In php, java, rails, or any other language, it takes 300ms to do this. – Amir Raminfar Jan 26 '11 at 14:41
  • @Amir Raminfar: Thanks for your time and concern :) – safi Jan 26 '11 at 14:48