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

Nesting SQL Server 2005 transactions in VB.NET

I have a situation where I have one procedure that executes a bunch of
database code in a transaction. In this procedure, in the middle of
the aforementioned transaction, I call another procedure that does a
series of things in yet another transaction. For some reason, after I
come back from the second procedure, where that transaction is
committed, and I try to run a simple SELECT SUM(*)... query in the
first one, it just times out. So, I am thinking it may be being caused
by the transaction stuff. My question relates to understanding the
proper way to code transactions within transactions. In case it's
relevant, these procedures are in different places (i.e. one in a
class, another in a form's code). Any insights would be greatly
appreciated.

A simplified version of what I have is something like follows:

Private Sub FirstProc()
Dim cnn As New
SqlClient.SqlConnection(My.Settings.MyConnectionSt ring)
cnn.Open()
Dim trx As SqlClient.SqlTransaction = cnn.BeginTransaction()

' Execute first command query
' Execute second command query
' Execute third command query

SecondProc()

' Try to execute SELECT SUM... FAILS with timeout

' Execute fourth command query
If (AllWentWell) Then
trx.Commit
Else
trx.Rollback
End If

'...

End Sub

Private Sub SecondProc()
m_cnn = New SqlClient.SqlConnection(My.Settings.GRPConnectionS tring)
m_cnn.Open()
m_cnnTransaction = m_cnn.BeginTransaction()

' Execute first command query
' Execute second command query
' Execute third command query

If (AllWentWell) Then
m_cnnTransaction.Commit
Else
m_cnnTransaction.Rollback
End If

'...

End Sub
Aug 6 '08 #1
1 1584
I would set up a test system (test DB) and then try executing your
queries in a stored procedure from Query Analyzer. If the SP works in
Query Analyzer then the query statements are OK and should work from the
sqlClient. But I will wager that you will encounter the same problem
using the SP that you are having with the sqlClient -- in which case you
need to modify the sql code.

If, however, the SP in query analyzer works fine, then I would consider
using a sqlDataAdapter instead of trying to run your transaction
directly from the sqlClient. You could run the SP directly from the
sqlDataAdapter.SelectCommand.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Aug 6 '08 #2

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

Similar topics

0
by: Ryan | last post by:
I am trying to use transactions in Access97 and SQL Server 2000. A simplified version of the program I am writing in Access is as follows: Begin Transaction Begin Transaction Import File in...
32
by: dreadnought8 | last post by:
I have a client who wishes to upsize an A97 system from Jet backend to SQL Server 2000. They have up to 4 users. Will they need to buy the minimal 5-seat SQL Server product, or would it be...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.