473,404 Members | 2,137 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,404 software developers and data experts.

Sql connection performance advice please!

I have a DB connection performance issue in my C# app.
I have used the Stopwatch to track how long it takes to do a couple
things.

Creating a SqlConnection object takes 19ms, and Opening a connection
(Sql2005) takes roughly 120ms.
Connecting to Sql2000 is around 64ms.
Does this sound correct, and can I speed this, since 140ms is
unacceptable for creating a connection in this app.

This was tested on a desktop PC. We have some older software which uses
Visual Basic code which connects a lot quicker.
On one Server (very high spec) we hav had all our Database activity done
in <1ms!

Any help on this would be appreciated.

Steven

*** Sent via Developersdex http://www.developersdex.com ***
May 11 '06 #1
7 2399

You need to provide the connection string, as alot of variables in it can
sometimes affect performance.


"Steven Blair" <st**********@btinternet.com> wrote in message
news:eX**************@TK2MSFTNGP05.phx.gbl...
I have a DB connection performance issue in my C# app.
I have used the Stopwatch to track how long it takes to do a couple
things.

Creating a SqlConnection object takes 19ms, and Opening a connection
(Sql2005) takes roughly 120ms.
Connecting to Sql2000 is around 64ms.
Does this sound correct, and can I speed this, since 140ms is
unacceptable for creating a connection in this app.

This was tested on a desktop PC. We have some older software which uses
Visual Basic code which connects a lot quicker.
On one Server (very high spec) we hav had all our Database activity done
in <1ms!

Any help on this would be appreciated.

Steven

*** Sent via Developersdex http://www.developersdex.com ***

May 11 '06 #2
Steven Blair wrote:
I have a DB connection performance issue in my C# app.
I have used the Stopwatch to track how long it takes to do a couple
things.

Creating a SqlConnection object takes 19ms, and Opening a connection
(Sql2005) takes roughly 120ms.
Connecting to Sql2000 is around 64ms.
Does this sound correct, and can I speed this, since 140ms is
unacceptable for creating a connection in this app.

This was tested on a desktop PC. We have some older software which
uses Visual Basic code which connects a lot quicker.
On one Server (very high spec) we hav had all our Database activity
done in <1ms!

Any help on this would be appreciated.


a first physical connection can take time. Though if you enable
connection pooling (it's enabled by default) you'll see that creating a
connection will take < 20ms after the first connection.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
May 11 '06 #3
I have tried using Sql Authentication and windows authentication. Both
are slow.

Regarding pooling, if this pseudo code mirrored my app, would 2nd
connection be quicker?:

Create SqlTransaction
Open Connection
Close Connection

Open Connection
Close Connection.

The problem I have, is my dll is created, Db connection opened, some Db
work, close connection, then dll is finished. That instance of the dll
wont be used again.
At some point a new instance will be created and we have to go through
all this again.

It really does seem quite a performance hit using these objects, and as
hard as it is for me to say, the Visual Basic code appears to be
quicker!
Steven
*** Sent via Developersdex http://www.developersdex.com ***
May 11 '06 #4
Here is an exmaple of a connection string:

Data Source=localhost;Initial Catalog="TS3 Help Desk";Persist Security
Info=True;User ID=sa

*** Sent via Developersdex http://www.developersdex.com ***
May 11 '06 #5
Steven,

If you are using SqlTransaction, you should create it after you open
your connection, and then assign it to any commands that are going to use
it. It's much slower to create the transaction first.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steven Blair" <st**********@btinternet.com> wrote in message
news:O3****************@TK2MSFTNGP02.phx.gbl...
I have tried using Sql Authentication and windows authentication. Both
are slow.

Regarding pooling, if this pseudo code mirrored my app, would 2nd
connection be quicker?:

Create SqlTransaction
Open Connection
Close Connection

Open Connection
Close Connection.

The problem I have, is my dll is created, Db connection opened, some Db
work, close connection, then dll is finished. That instance of the dll
wont be used again.
At some point a new instance will be created and we have to go through
all this again.

It really does seem quite a performance hit using these objects, and as
hard as it is for me to say, the Visual Basic code appears to be
quicker!
Steven
*** Sent via Developersdex http://www.developersdex.com ***

May 11 '06 #6

"Steven Blair" <st**********@btinternet.com> wrote in message
news:eX**************@TK2MSFTNGP05.phx.gbl...
|I have a DB connection performance issue in my C# app.
| I have used the Stopwatch to track how long it takes to do a couple
| things.
|
| Creating a SqlConnection object takes 19ms, and Opening a connection
| (Sql2005) takes roughly 120ms.
| Connecting to Sql2000 is around 64ms.
| Does this sound correct, and can I speed this, since 140ms is
| unacceptable for creating a connection in this app.
|
| This was tested on a desktop PC. We have some older software which uses
| Visual Basic code which connects a lot quicker.
| On one Server (very high spec) we hav had all our Database activity done
| in <1ms!
|
| Any help on this would be appreciated.
|
| Steven
|
|
|
| *** Sent via Developersdex http://www.developersdex.com ***

The first connection involves authentication plus the establishment of a
physical DB connection, authentication is the most expensive part, but 120
msec. looks real good.
The second connection (in the context of the same process) will use a
connection from the pool (the same as used before), should take less than a
tenth of a millisecond.

Willy.


May 11 '06 #7
Sorry, my bad.
SqlTransaction should have been SqlConnection.

No Transactions are being used in this example.

*** Sent via Developersdex http://www.developersdex.com ***
May 11 '06 #8

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

Similar topics

6
by: Paul Robinson | last post by:
I am developing a website in ASP that connects to a Sybase database. However, when I try to open a connection to the database the page will not load. The script does not timeout, nor the...
1
by: Mithun Verma | last post by:
Hello All, I am working on a windows application which will talk to the database through the Web services. So i need to enhaance the performance, for which i m using connection
5
by: Mojtaba Faridzad | last post by:
Hi, (newbie in C#) is it a good idea to use SQL Connection, SQL Data Adapter,... in C#? when I am design a form, I can use SQL Connection and set the properties to connect to a database. I guess...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
8
by: serge calderara | last post by:
dear all, i have an application which could have more than 150 users, I have set it up to use windows integrated authentification. What I have to do to be sure that my application will use...
5
by: mjan | last post by:
Hello, could you please advice on how to measure replication performance in Oracle, DB2 & MS SQL Server RDBMS installed in Windows servers ? I've got two servers with databases installed and...
16
by: crbd98 | last post by:
Hello All, Some time ago, I implemented a data access layer that included a simple connectin pool. At the time, I did it all by myself: I created N connections, each connection associated with...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.