Parallelism in Sql Server with C #

1

I'm implementing async methods in C # and would like to know how to proceed when I get into Sql.

When I open a connection to the sql server, does it allow me to parallelize only one connection? That is, can I send several queries to him that he executed in parallel?

If so, what is the maximum number of parallel queries it can do in parallel?

If not, do I need several different connections so he understands he can do it all at the same time?

For any of the answers I need to set up something in sql or queries (be they SP or commands)?

    
asked by anonymous 21.08.2017 / 18:09

2 answers

0

Fernando, The Sql Server accepts multiple queries from a single connection. The biggest question here is: what operation will you perform in parallel? When there is concurrency in the database (multiple concurrent accesses) locks / locks may occur in addition to Deadlocks . If they are read operations, see if there is a need to perform clean readings (ie with the most recent position of the database, waiting for there to be no locking in the tables to read), if not, use ( nolock) from from and be happy. Now, if they are include, change, and delete operations, there may be many locks and deadlocks and your bank will crash. In this case, you can rehash the changes during parallel processing on the application side and apply changes to the batch database.

    
21.08.2017 / 22:39
1

According to this link ( link ), if the If your .Net version is less than 4.5, then you must enter Asynchronous Processing=true in your connection object. Otherwise the SqlDataReader has async methods for read / write.

  

When I open a connection to the sql server, does it allow me to parallelize only one connection? That is, can I send several queries to him that he executed in parallel?

Yes

  

If yes, what is the maximum number of parallel queries it can do in parallel?

I do not have an exact number, but probably the limit of concurrent queries that sql server supports

  

For any of the answers I need to set up something in sql or queries (be they SP or commands)?

As I understand who will wait for the asynchronous response would be your C # application, not the SQL Server itself, then who should do the async query is the client and your SP / Trigger should be written by default. p>

There are other considerations that I will not go into deeply here because it was not the focus of your question, such as polling and events, which are the ways to wait for a query to be executed. In this specific case I suppose it is event by callback and await .

Example (If the .Net version

21.08.2017 / 23:43