Form waiting for a request

Asked

Viewed 166 times

3

Problem


My form makes a statement requisição a database (select, insert, update, delete values), but whenever these requests are made a lock occurs in the form (a freeze)! How to prevent forms from receiving these locks regardless of request?


Observing: The longer the request takes the longer the lock. An example is a select * from tabela; that capture a large amount of values in the database. I’ve had both problems in JAVA and C#.

Heed: when I say request I am referring to connection and search in the database.

  • 2

    Are you talking about ajax requests made with Javascript? In this case, you should use an asynchronous request instead of synchronous.

  • How are you doing these requests, by ajax? By chance you are using async: false? If you are, you have to change that.

  • I’m with @bfavaretto on this, regarding what I understood of your question.

  • @bfavaretto good do not use web languages in these projects, are form (Windows) desktop. The window that ends up freezing until the request to the bank ends.

  • Ah, now it’s clear. So look at Danimar Ribeiro’s answer, I think that’s what you’re looking for.

  • 2

    select * from tabela every request? Something is much wrong there.

  • A form has the function of generating a report! By clicking the button the report is generated with database values. Should I say that a request was made to the database? @Ciganomorrisonmendez.

  • @Eduardobentorochajunior there are several optimizations to do: do not use select *is just one of them. You can implement paging, caching... It would be excellent beginnings to make your search more performative. On the BD side, create the relevant indexes, etc

  • Got it, thanks @Tiagocésaroliveira I will research on the subject. I passed the example of select * from tabela as a simple way that everyone understands.

Show 4 more comments

3 answers

5

If your problem is to query a large amount of data, no matter the language, a direct query will always lock (lock in the process) while waiting for the return of the database.

The best alternative is to perform an asynchronous query, that is, the process (thread) that makes the query does not need to be blocked waiting for the database response, in this case there will be a callback method to receive the response from the database when it is finished being consulted.

Here is a link explaining how to perform this type of query simplest way in C#:

In version 5.0 of C# magic words were included async and await that resolve callback. Here is a link explaining this usage:

2

Some points could be taken into consideration for an optimization:

  • Does your table have indexes correctly created? If you make a query using LIKE and the table is large, without index, the performance will be impaired.
  • Are you searching for an ID? At the time of a delete or update, the key is the table ID? This can also influence.
  • When searching for data do not select * from, but describe each attribute select fieldA, fieldB from.
  • If the table has a lot of data the correct one is to make a page query. Search little by little the information.
  • In the case of a CRUD is not much advised paging as the user expects an immediate response to its action. The user usually wants immediate feedback for a CRUD action - usually something very simple.

If your table is too large (millions of records) you could use techniques to decrease the table size:

  • Break the table (Personsnomeabc, Personsnomedef,...)
  • Partition by own database resources (several databases already have this functionality)
  • Reduce the number of indexed columns

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.