Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Should I reuse Npgsql connections in a C# application?

Posted on 2016-10-31
3
Medium Priority
?
333 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 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 1000 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 1000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

604 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