In some cases, when every milisecond counts, you might need to execute several stored procedures at the same time. At the same time here means that when calling the first stored procedure, you don't want to wait for its result in order to call the second one.
In other words, if the two stored procedures are independent, it would be a brilliant idea to improve performance by executing them in parallel.
Say, for example, that you have two stored procedures: SP1 and SP2. Everyone of them takes 3 seconds. If you want to call them in sequence, this would mean you'll need to wait for 6 seconds. Calling them in parallel will let them both execute in around 3 seconds.
In this article, I will give an example of an ASP.NET web page that calls 2 parallel stored procedures in its load method.
Let's say that you have 2 stored procedure named SP1 and SP2. Everyone of them returns a result set. Every result set is independent from the other. For simplicity, I'll say that you are only interested in the first record of the result set and you want to display this value in a
If you want to call them sequentially, or synchronously, this would typically be what you write:
However, if you want to call them asynchronously, you need to create to different connections. They can both use the same connection string. In addition, you'll need to use
Your code will look more like this:
In other words, if the two stored procedures are independent, it would be a brilliant idea to improve performance by executing them in parallel.
Say, for example, that you have two stored procedures: SP1 and SP2. Everyone of them takes 3 seconds. If you want to call them in sequence, this would mean you'll need to wait for 6 seconds. Calling them in parallel will let them both execute in around 3 seconds.
In this article, I will give an example of an ASP.NET web page that calls 2 parallel stored procedures in its load method.
Let's say that you have 2 stored procedure named SP1 and SP2. Everyone of them returns a result set. Every result set is independent from the other. For simplicity, I'll say that you are only interested in the first record of the result set and you want to display this value in a
Literal
control.If you want to call them sequentially, or synchronously, this would typically be what you write:
protected void Page_Load(object sender, EventArgs e) { SqlConnection cnn = new SqlConnection("Your connection string"); SqlCommand cmd1; SqlCommand cmd2; SqlDataReader reader1; SqlDataReader reader2; try { cnn.Open(); cmd1 = new SqlCommand("SP1", cnn); cmd1.CommandType = System.Data.CommandType.StoredProcedure; reader1 = cmd1.ExecuteReader(); if (reader1.Read()) { Literal1.Text = reader1[0].ToString(); } if (!reader1.IsClosed) { reader1.Close(); } cmd2 = new SqlCommand("SP2", cnn); cmd2.CommandType = System.Data.CommandType.StoredProcedure; reader2 = cmd2.ExecuteReader(); if (reader2.Read()) { Literal2.Text = reader2[0].ToString(); } if (!reader2.IsClosed) { reader2.Close(); } } catch (Exception ex) { // raise an exception or do whatever logic you want } finally { if (cnn.State != System.Data.ConnectionState.Closed) cnn.Close(); } }
However, if you want to call them asynchronously, you need to create to different connections. They can both use the same connection string. In addition, you'll need to use
BeginExecuteReader
and EndExecuteReader
instead of the usual ExecuteReader
Your code will look more like this:
protected void Page_Load(object sender, EventArgs e) { SqlConnection cnn1 = new SqlConnection("Your connection string"); SqlConnection cnn2 = new SqlConnection("Your connection string"); SqlCommand cmd1; SqlCommand cmd2; IAsyncResult result1; IAsyncResult result2; SqlDataReader reader1; SqlDataReader reader2; try { cnn1.Open(); cmd1 = new SqlCommand("SP1", cnn1); cmd1.CommandType = System.Data.CommandType.StoredProcedure; result1 = cmd1.BeginExecuteReader(CommandBehavior.SingleRow); cnn2.Open(); cmd2 = new SqlCommand("SP2", cnn2); cmd2.CommandType = System.Data.CommandType.StoredProcedure; result2 = cmd2.BeginExecuteReader(CommandBehavior.SingleRow); reader1 = cmd1.EndExecuteReader(result1); if (reader1.Read()) { Literal1.Text = reader1[0].ToString(); } reader1.Close(); reader2 = cmd2.EndExecuteReader(result2); if (reader2.Read()) { Literal2.Text = reader2[0].ToString(); } reader2.Close(); } catch (Exception ex) { // raise an exception or do whatever logic you want } finally { if (cnn1.State != System.Data.ConnectionState.Closed) cnn1.Close(); if (cnn2.State != System.Data.ConnectionState.Closed) cnn2.Close(); } }
Heya і аm for tҺe first time hеre. І camе аcross tɦis
ReplyDeleteboard аnd I find It reallу սseful & it helped me out mucҺ.
І hope tօ gikve somеthing bacҡ and help ߋthers like
you aided me.
Lߋok ɑt my homepage; mp3 volume enhancer ()
using statements !
ReplyDeleteThis is very good content you share on this blog. it's very informative and provide me future related information.
ReplyDeleteData Science course in kalyan nagar
Data Science course in OMR
Data Science course in chennai
Data science course in velachery
Data science course in jaya nagar
Data Science interview questions and answers
Data science course in bangalore
Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
ReplyDeletepython training in bangalore
This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me. Keep it up!!
ReplyDeleteMachine Learning Course
It’s good to check this kind of website. I think I would so much from you. ExcelR Machine Learning Course Pune
ReplyDeleteI want like this topic. thank u
ReplyDeletepython training in chennai
python online training in chennai
python training in bangalore
python training in hyderabad
python online training
python flask training
python flask online training
python training in coimbatore
I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
ReplyDeleteI read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community. data science courses
ReplyDeleteYour post is very great.i read this post this is a very helpful. i will definitely go ahead and take advantage of this. You absolutely have wonderful stories.Cheers for sharing with us your blog. python training in noida
ReplyDeleteangular js training in chennai
angular js training in tambaram
full stack training in chennai
full stack training in tambaram
php training in chennai
php training in tambaram
photoshop training in chennai
photoshop training in tambaram
Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
ReplyDeleteoracle training in chennai
oracle training in omr
oracle dba training in chennai
oracle dba training in omr
ccna training in chennai
ccna training in omr
seo training in chennai
seo training in omr
Good Post! , it was so good to read and useful to improve my knowledge as an updated one, keep blogging.After seeing your article I want to say that also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts likethis.
ReplyDeletehttps://www.3ritechnologies.com/course/selenium-online-training/
seo india tools are better to improve search engine.
ReplyDeleteIf you are trying to get ahead of the competition in
ReplyDeletethe search engine results pages, you should try purchasing SEO group buy tools.
Group Buy SEO ToolsGroup Buy SEO Tools offer a huge load of uncommon features which produce outstanding results. These SEO devices are used by SEO trained professionals and progressed promoters to drive more traffic to destinations. our organizations are open to SEO beginners, digital advertisers and on a limited financial plan.
ReplyDeleteWonderful blog post.
ReplyDeleteJuan Francisco Estrada vs Roman “Chocolatito� Gonzalez Live
estrada vs chocolatito 2 live stream free
This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea.
ReplyDeletedata scientists training
StockTrim is inventory planning and demand forecasting software available as a subscription. It helps SME's gain optimised inventory levels and preserves up to 40% of their working capital.Stock Control
ReplyDeleteGood job.
ReplyDeleteon our movie website have compiled both old movies and new movies for you to watch Online movie theaters. ดูหนัง (Watch movies) online for free.
ReplyDeleteReally an awesome blog, with informative and knowledgeable content. Thanks for sharing this blog with us. Keep sharing more stuff again.
ReplyDeleteAI Patasala Data Science Training
MMORPG OYUNLAR
ReplyDeleteİnstagram Takipçi Satın Al
Tiktok jeton hilesi
Tiktok jeton hilesi
Sac Ekim Antalya
Takipci Satın Al
instagram takipçi satın al
Metin Pvp
instagram takipçi satın al
özel ambulans
ReplyDeleteminecraft premium
en son çıkan perde modelleri
en son çıkan perde modelleri
nft nasıl alınır
yurtdışı kargo
uc satın al
lisans satın al
Good text Write good content success. Thank you
ReplyDeleteslot siteleri
betmatik
kibris bahis siteleri
betpark
mobil ödeme bahis
poker siteleri
tipobet
kralbet
kocaeli
ReplyDeletekonya
kuşadası
kütahya
malatya
İZ27D
başakşehir
ReplyDeletebeykoz
gölcük
kütahya
bandırma
64İ5FU
Discovering the power of making parallel database calls has been a game-changer. Set Up A Server For Web Hosting It significantly improves application performance and responsiveness.
ReplyDeletebitlis
ReplyDeletekastamonu
artvin
ısparta
hatay
6JGKL
شركة تنظيف فلل بالقطيف
ReplyDeleteتنظيف فلل
شركة تنظيف بالقطيف 2Av42mfGtR
ReplyDeleteشركة مكافحة النمل الابيض بالخبر 79X31RbCo7
ReplyDelete