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 / New Users / July 2006

Tip: Looking for answers? Try searching our database.

Connection timeout when using transactions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Natan Vivo - 12 Jul 2006 16:05 GMT
I'm getting a timeout error while trying to select data from SQL server
2005 after opening a transaction in asn asp.net application.

It goes like this:

SqlConnection conn1 = new SqlConnection(...);
conn1.Open();
SqlTransaction trans = conn1.Open();

// do some inserts and updates using the transaction

SqlConnection conn2 = new SqlConnection(...);
conn2.Open();

// select using conn2 and decide what to do

conn2.Close();

// do more inserts and updates based on that decision

trans.Commit();
conn1.Commit();

It probably has something to do with the connection pool returning the
already open conn1 to connection2.

In the actual process, the select using the 2nd connection is being
opened in another method, and I don't want to overload the method to
receive the transaction.

Is there any other option? Is there any way to really open another
connection, or the connection pool to not return open connections being
used in transactions?

Thanks.
Tracy McKibben - 12 Jul 2006 16:26 GMT
> I'm getting a timeout error while trying to select data from SQL server
> 2005 after opening a transaction in asn asp.net application.
[quoted text clipped - 31 lines]
>
> Thanks.

Have you changed the default CommandTimeout from the default?  I think
the default for ASP/ASP.NET is 30 seconds.

Signature

Tracy McKibben
MCDBA
http://www.realsqlguy.com

Natan Vivo - 12 Jul 2006 16:33 GMT
> Have you changed the default CommandTimeout from the default?  I think
> the default for ASP/ASP.NET is 30 seconds.

No, and it is not the problem. The whole process takes less than 1 second.

The thing is exactly what I told. If I open an second connection and
select something, while connection one is in transaction, it hangs and
gives me a connection timeout.

Can anyone reproduce this?
Tracy McKibben - 12 Jul 2006 16:46 GMT
>> Have you changed the default CommandTimeout from the default?  I think
>> the default for ASP/ASP.NET is 30 seconds.
[quoted text clipped - 6 lines]
>
> Can anyone reproduce this?

Not knowing what selects you're running in connection 2, I'd have to say
you're probably deadlocking against the open transaction in connection 1.

http://realsqlguy.com/twiki/bin/view/RealSQLGuy/SimulatingADeadlock

Signature

Tracy McKibben
MCDBA
http://www.realsqlguy.com

Natan Vivo - 13 Jul 2006 14:01 GMT
>>> Have you changed the default CommandTimeout from the default?  I
>>> think the default for ASP/ASP.NET is 30 seconds.
[quoted text clipped - 12 lines]
>
> http://realsqlguy.com/twiki/bin/view/RealSQLGuy/SimulatingADeadlock

Thanks. It was really a deadlock, the select was selecting data from the
same table I had already update.

It seems I can solve this by using the right IsolationLevel when
begining the transaction.

I'll test it later. Thanks!
Tracy McKibben - 13 Jul 2006 14:12 GMT
> Thanks. It was really a deadlock, the select was selecting data from the
> same table I had already update.
[quoted text clipped - 3 lines]
>
> I'll test it later. Thanks!

Be careful that you're not reading "dirty" data, meaning data that is
inconsistent because it's been partially altered by a transaction...

Signature

Tracy McKibben
MCDBA
http://www.realsqlguy.com

Neil B - 12 Jul 2006 17:30 GMT
>> Have you changed the default CommandTimeout from the default?  I think
>> the default for ASP/ASP.NET is 30 seconds.
[quoted text clipped - 6 lines]
>
> Can anyone reproduce this?

Yes, I had the exact same problem in an application of mine. In the
absence of finding a solution, I coded around it. Sorry I can't be of
more help, but you're not alone. :)

Neil B
Damien - 13 Jul 2006 08:07 GMT
> I'm getting a timeout error while trying to select data from SQL server
> 2005 after opening a transaction in asn asp.net application.
[quoted text clipped - 21 lines]
> It probably has something to do with the connection pool returning the
> already open conn1 to connection2.

No, that's not how the connection pool works. If you have two open
connections in your code, you'll be using two connections from the
connection pool.

> In the actual process, the select using the 2nd connection is being
> opened in another method, and I don't want to overload the method to
[quoted text clipped - 5 lines]
>
>From your description, it's almost certainly a deadlock on sql server.
Without seeing the database code, it's going to be difficult to help
you out.

To confirm it's a deadlock, open a connection using query analyser,
start your code running, then run sp_who2. It'll show your second
connection being blocked by your first.

Damien

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.