473,383 Members | 1,978 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,383 software developers and data experts.

Using multiple SqlConnection objects, bad for performance?

Hello,

I am planning to use three databases on the local SQL Server. DB1 will be
for App1, DB2 for App2, and DB3 will hold tables, that both, App1 and App2
need to access.
With applications I mean ASP.NET applications.
Obviously, I need in App1 and App2 at least two SqlConnection and SqlCommand
objects, one that access their respective databases, and one that will access
DB3.
Will this result in a worse performance? (The using of two SqlConnection
objects in one aspx page as example, and switching them)
Should I for better performance get rid of DB3 and add the tables there to
DB1 and DB2 ? (Thus multiplying data, but, if the performance will be much
better, it will be fine with me)
I would be thankful for any advices.
Feb 9 '07 #1
4 1684
Thus wrote the friendly display name,
Hello,

I am planning to use three databases on the local SQL Server. DB1 will
be for App1, DB2 for App2, and DB3 will hold tables, that both, App1
and App2 need to access.

With applications I mean ASP.NET applications.

Obviously, I need in App1 and App2 at least two SqlConnection and
SqlCommand objects, one that access their respective databases, and
one that will access DB3.
That sounds suspiciously as though you want to use global connection objects.
Forget about that. Open a connection only when you need it, and close it
immediately after you're done.
Will this result in a worse performance? (The using of two
SqlConnection objects in one aspx page as example, and switching them)
It depends on your transaction boundaries and what API you use for transactions
(System.EnterpriseServices, System.Data, System.Transactions, ...). What
you definitely want to avoid is accidentally ending up with a global transaction
where a local transaction would have sufficed (that can even happen with
a single DB).

If eliminating DB3 makes sense depends on whether and how both applications
contend for the same resources. I don't think that there's a general answer
to that question.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Feb 10 '07 #2
"the friendly display name"
<th********************@discussions.microsoft.comw rote in message
news:D4**********************************@microsof t.com...
Obviously, I need in App1 and App2 at least two SqlConnection and
SqlCommand
objects, one that access their respective databases, and one that will
access
DB3.
Er, no... What you need (OK, what I would recommend...) is that you use a
DAL (database abstraction layer) based on the Microsoft one
(http://msdn2.microsoft.com/en-us/library/aa480458.aspx) which will create
an internal connection object and command objects (and any other type of
ADO.NET object) as and when required, and destroy them immediately they are
no longer needed.

Since you have three databases, you will probably end up with three
individual connection strings which will, in turn, mean that you will have
three separate connection pools from which the connection objects will be
reused by the DAL to speed things up even further. Under normal
circumstances, this should just happen automatically for you without any
additional coding.
Will this result in a worse performance? (The using of two SqlConnection
objects in one aspx page as example, and switching them)
Using a DAL means that you never need to use any SqlConnection or SqlCommand
objects in your page at all...
Feb 10 '07 #3
the friendly display name wrote:
Hello,

I am planning to use three databases on the local SQL Server. DB1 will be
for App1, DB2 for App2, and DB3 will hold tables, that both, App1 and App2
need to access.
With applications I mean ASP.NET applications.
Obviously, I need in App1 and App2 at least two SqlConnection and SqlCommand
objects, one that access their respective databases, and one that will access
DB3.
Will this result in a worse performance? (The using of two SqlConnection
objects in one aspx page as example, and switching them)
Should I for better performance get rid of DB3 and add the tables there to
DB1 and DB2 ? (Thus multiplying data, but, if the performance will be much
better, it will be fine with me)
I would be thankful for any advices.
I don't really see any reason to have more than one database. If the
applications will have some of their data in a shared database, they
could just as well have all their data in that database.

--
Göran Andersson
_____
http://www.guffa.com
Feb 10 '07 #4
Hi,

no, I am not using global connection objects, I usualy close connections
immediately too, the two possible connections will not be open at the same
time.

I am using System.Data.

My main question is, will pooling stop working, or be inefficent, or some
other great slowdown, based on the architecture of .net and sql server, if I
use a second SqlConnection object with anohter connection string in a aspx
page?

"Joerg Jooss" wrote:
That sounds suspiciously as though you want to use global connection objects.
Forget about that. Open a connection only when you need it, and close it
immediately after you're done.
Will this result in a worse performance? (The using of two
SqlConnection objects in one aspx page as example, and switching them)

It depends on your transaction boundaries and what API you use for transactions
(System.EnterpriseServices, System.Data, System.Transactions, ...). What
you definitely want to avoid is accidentally ending up with a global transaction
where a local transaction would have sufficed (that can even happen with
a single DB).

If eliminating DB3 makes sense depends on whether and how both applications
contend for the same resources. I don't think that there's a general answer
to that question.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Feb 10 '07 #5

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

Similar topics

26
by: codymanix | last post by:
Last night I had several thought about RAII and want to discuss a bit. Why doesn't CSharp support destructors in structs? Wouldn't that make RAII possible like in C++? When the struct goes out of...
19
by: Kamilche | last post by:
I have looked at many object-oriented programming frameworks out there for C. Though the ideas presented are intriguing, and I've used some of them in my own work, they all suffered some drawback...
4
by: Peter Kirk | last post by:
Hi I have some code in C# for accessing a database. For example: using (SqlConnection conn = GetConnection() ) { using (SqlCommand command = new SqlCommand( ... { ... }
11
by: Bob | last post by:
In our new .NET web applications, we try to limit the use of SqlConnection to just one instance per page, even if there are multiple accesses to various queries. The thinking behind is that this...
3
by: Daves | last post by:
Please take your time to read the following, it's simple although the text is 3 paragraphs... Everytime an user is logged in I need to make a call to my sql server database to grab some specific...
4
by: Victor | last post by:
Hi Guys I have a problem here. I want to improve the performance for a website. When I looked into the system, I have found that the system made the "SqlConnection Object" static. That mean only...
2
by: | last post by:
I am using a datareader to cycle through a list of records one at a time. I frequently get connection timeouts and am wondering what I am doing wrong. In more detail, I retrieve an excel...
0
by: David | last post by:
- Are there any peculiarities with using curs.executemany(...) vs. multiple How many times are you calling execute vs a single executemany? The python call overhead will add up for thousands of...
1
by: bizt | last post by:
Hi, Im currently looking to move into using JSON for AJAX instead of returning from the server a string like the following: 12345{This is a text string{true I prefer objects because I dont...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.