473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Share ADO.NET database connection across projects.

Hi,

I have a C# Solution/Application that contain 4 projects.

Each of these projects needs at some time to access the same database.

I would like to know how to share a single connection between these projects
as i assume this would be more efficient than having a separate connection
string for each project.

Also what is the best way to control the opening and closing of the database
in these projects through this connection string.

When is it best to access the database directly and when is it best to go
through a dataset?

Thanks In Advance
Macca
Nov 17 '05 #1
1 3363
Macca,

In order to share the same connection across projects, I would have one
assembly that all the projects reference. This assembly would have a type
in it which would expose a static member which would return your connection
to you, configured properly.

This leads into how to control the opening and closing of the
connection. The method should return a new connection, not an instance of a
connection you share among everyone. Whether or not to open the connection
before passing it back is up to you.

Now, when you return your connection, you should use it in a using
statement, so that the connection is disposed/closed properly when you are
done with it. Whenever you get a database connection, you should get the
connection, do your work, and close it as soon as possible.

As for when it is best to access the database directly, I don't know
what you mean by that. In .NET, when you get data, you get a DataSet, which
is populated with the data, or use a data reader, which allows you to cycle
through the returned result set. The data adapter, in reality, just cycles
through a data adapter and populates the data set.

As for updating a database, you can use command objects directly, but
using data adapters is much easier.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Macca" <Ma***@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
Hi,

I have a C# Solution/Application that contain 4 projects.

Each of these projects needs at some time to access the same database.

I would like to know how to share a single connection between these
projects
as i assume this would be more efficient than having a separate connection
string for each project.

Also what is the best way to control the opening and closing of the
database
in these projects through this connection string.

When is it best to access the database directly and when is it best to go
through a dataset?

Thanks In Advance
Macca

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: TaeHo Yoo | last post by:
Hi all, We have three web based applications (A, B and C) and they are kept on different source safe database say SourceSafeA, SourceSafeB and SourceSafeC respectively. A solution contains aa...
2
by: TaeHo Yoo | last post by:
Hi all, I have a solution which contains multiple projects. Those multiple projects should share the same session. For example, users login, create the session for users then these session...
7
by: isamusetu | last post by:
anybody knows how to share the dll between the process? I know there is a way to set the #pragma data_seg in the visual studio 6.0 C++, that can make the dll can be shared between the multiple...
5
by: Rich | last post by:
Hi there, For a quite big application, I need to get large amount of data within a static library (xxx.lib) and put them in a database (a class, say we call it CData), and then make it...
1
by: Simon Harris | last post by:
Hi All, I have this in an ASCX file: <%@ Control Language="vb" %> <%@import namespace="System.Data.OleDb"%> <Script runat="Server"> Public Function GetConnection() Dim Conn as OleDbConnection...
4
by: dx | last post by:
I have 3 vb.net web applications. I would like all 3 to have access to a library of user controls. server controls wouldn't cause a problem but these are user controls (ascx.) From each solution...
2
by: Ahmed | last post by:
Dear All, I have three web applications that I want to provide one single web interface to all of them. If I am able to share the session between them, It will be great. so is this possibel?
3
by: Ron L | last post by:
I have an application that I am developing that is a front end for a SQL database. We will also be developing a subset of the UI that will work as a (mainly) standalone client that will make a...
4
by: dougans | last post by:
Hey there, Hope someone can help me, completely stuck with immigrating from php4 to OOP based php5. == index.php -- include(database.inc.php);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.