c#/ sql-server/ sql-server-2012/ task-parallel-library/ executenonquery

I'm using Serenity C# to develop a website.

When I click on a button it should run a SQL command, which starts a stored procedure.

My code

public ListResponse<MyRow> RunSQL(IDbConnection connection, ListRequest request)
{
    string sql = "EXEC SP_A @Username='" + Authorization.UserDefinition.Username + "'";
    SqlHelper.ExecuteNonQuery(connection, sql);
    return new MyRepository().List(connection, request);
}

This code works fine, but it makes my web slow because my web needs to wait for the query to finish.

I want to kick off the SQL command and not wait for the result. Can I use the Task Parallel Library (TPL) for this?

Can I use TPL (Task Parallel Library)??

No, you can not. You execute ONE statement, I am not even sure where you get the idea that paralellism of one item will do anything. if that query takes a long time, analyze whether it is defective. if it is not defective...

...change the API to be async an return a come back later with a token. It is waiting for the return value because you degiend the API to be synchroneous. you this is not acceptable, then the API is a design error and the design at least of this method should change.

Nothing in async/await/paralellism will change the API design and it will not magically make the request finish faster.

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Different result running a query in SQL Server and from C# Retrieve Parent / Child Query result SQL Server with c# Wait for a specific result from Task then run another method in C# run database query and not wait for result C# SQL Server query SQL query doesn't return the same result in SQL Server and in C# C# SQL Query continous return of result C# with sql query result to variable SQL query to scalar result in C# C# SQL query result to textboxes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM