Solved

Should I reuse Npgsql connections in a C# application?

Posted on 2016-10-31
3
216 Views
Last Modified: 2016-11-01
Hi:

I've got a C# method that, during it's course of execution, is running several queries using npgsql.
I have several queries to gather data from different sources (tables), and then a query to insert
the results into a separate table.

Is it best in this scenario to reuse the NpgsqlConnection for all the queries, or use a
separate NpgsqlConnection for each query.

I'm new to npgsql and not sure what the best practice would be in terms of
performance and reliability.

Thanks,
JohnB
0
Comment
Question by:jxbma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Assisted Solution

by:Ryan Chong
Ryan Chong earned 250 total points
ID: 41867903
what the best practice would be in terms of performance and reliability
that would mean that we try to reduce the opened connection to your database, and we certainly hope that in one connection request, we finished all the tasks as possible as we can. and we probably can do it via database's stored procedures. (meaning do your stuff at database end)

Check the advantages and disadvantages from this article:

Introduction to PostgreSQL Stored Procedures
http://www.postgresqltutorial.com/introduction-to-postgresql-stored-procedures/
0
 
LVL 14

Accepted Solution

by:
Phil Phillips earned 250 total points
ID: 41867916
It's better to reuse the same connection.  There's overhead associated with opening a new connection.  If it's already open, might as well use it.
0
 
LVL 1

Author Closing Comment

by:jxbma
ID: 41868500
I'm new to postgresql, so I just wanted to make sure standard DB strategies still apply.
Thx!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question