Solved

Should I reuse Npgsql connections in a C# application?

Posted on 2016-10-31
3
120 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
3 Comments
 
LVL 51

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 13

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applicationsā€¦
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the reā€¦
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.

831 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