M
M
mletov2018-01-09 14:09:10
ASP.NET
mletov, 2018-01-09 14:09:10

How to wait for the response of sql query execution?

There is a rather long running SQL query
In C # I fill the List through it through EF in this way

lstGrafic = db.Database.SqlQuery<GraficInfo>(
                                                            s,
                                                            new SqlParameter("@dateStart", this.dateStart)
                                                        )
                                                        .OrderBy(x => x.VD)
                                                        .ToList();

I get an error
System.ComponentModel.Win32Exception (0x80004005): Operation timed out

If you go through the debugger step by step or just put it after
Thread.Sleep(30 * 1000);
, then everything works out the rules.
But this approach seems to me a crutch. Are there any good practices for properly handling waiting for a result from a sql query?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Makarov, 2018-01-09
@mletov

Use async/await. You need to wait in a separate thread.

K
Konstantin Borovik, 2018-01-09
@PushMeNow

use the TPL library or async/await. it's just that when you need a response from the database, just turn on the "wait" method (the wait method for TPL, await for async) and when it works, do whatever you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question