Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / April 2006

Tip: Looking for answers? Try searching our database.

SqlConnection.open() slow in 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Chapman - 04 Apr 2006 14:58 GMT
Hi

I have been using the SqlConnection class in version 1.1 for a while with no
problems.  I have now converted my code across to version 2.0 and the open is
now incredibly slow.  The exact same code takes 20 seconds to open the
connection when compiled using 2.0 and opens almost instantly when compiled
using 1.1.  I have also tried using OleDb instead of SqlClient and this works
fine in 2.0 opening the connection almost immediately.

DateTime startTime = DateTime.Now;
System.Data.SqlClient.SqlConnection connection = new
System.Data.SqlClient.SqlConnection();
connection.ConnectionString = "Data Source=Server1; Initial Catalog=Master;
Integrated Security=SSPI; Connect Timeout=100;";
connection.Open();
System.Data.SqlClient.SqlCommand command = new
System.Data.SqlClient.SqlCommand();
command.Connection = connection;
command.CommandText = "sp_who";
command.CommandType = CommandType.StoredProcedure;
System.Data.SqlClient.SqlDataReader dataReader = command.ExecuteReader();
dataReader.Close();
connection.Close();
MessageBox.Show("Time = " + (DateTime.Now - startTime).ToString());

Thanks in advance
Peter
Robbe Morris [C# MVP] - 05 Apr 2006 02:07 GMT
I have not noticed that at all.  And, you are timing far more than
the connection.Open.  Are you sure that is where the slowness resides?

Signature

Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp

> Hi
>
[quoted text clipped - 28 lines]
> Thanks in advance
> Peter
Peter Chapman - 05 Apr 2006 08:44 GMT
It us undoubtably the connection open as I have timed that bit independantly
as well.  I added the code to ensure that the connection was really open in
both cases.

> I have not noticed that at all.  And, you are timing far more than
> the connection.Open.  Are you sure that is where the slowness resides?
[quoted text clipped - 31 lines]
> > Thanks in advance
> > Peter
Peter Chapman - 05 Apr 2006 11:49 GMT
After two days of hell I have finally solved this one.
It turns out that the cause of my problems stem from the windows firewall
being on on the server computer.  It apears that my code was hanging while it
waited for the tcp/ip to timeout before it gave up and decided to use named
pipes.  I guess 2.0 must try tcp before named pipes - I'm surprised this
isn't documented anywhere though!

> It us undoubtably the connection open as I have timed that bit independantly
> as well.  I added the code to ensure that the connection was really open in
[quoted text clipped - 35 lines]
> > > Thanks in advance
> > > Peter

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.