473,465 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Advice on using transactions

All

I want to use sql transactions on one of my forms as I have multiple updates
to tables to perform and want all or none to commit.

The problem I've got is that each update to a table is done using a
different class and the try, catch block is in a separate database connection
class, which means (as I understand it) transactions won't work. Here's a
simplified version of my code:

Form code:

If deptrecordValid = True and adminrecordValid = True Then
dim currentDept as New Department
currentDept.Dept = Me.tbDept.Text
currentDept.DeptCurrent = Me.cbCurrent.Checked
'this is the first table save
currentDept.SaveRecord()
dim currentDeptAdmin as New DeptAdmin
currentDeptAdmin.Dept = Me.tbDept.Text
currentDeptAdmin.User = Me.ddlAdmin.SelectedValue
'this is the second table save
currentDeptAdmin.SaveRecord()
End If

currentDept.SaveRecord() looks like this (currentDeptAdmin.SaveRecord()
follows the same format).

With New DBConnection
'firstly add the parameters
.AddParameter("@dept", SqlDbType.VarChar, 50, dept)
.AddParameter("@deptcurrent", SqlDbType.Bit, 0, deptCurrent)
'then commit the data
.ExecNonQuerySP("sp_InsertDept")
End With

DBConnection looks like this:

Public Sub AddParameter(ByVal ParamName As String, ByVal paramType As
Data.SqlDbType, ByVal Paramlenght As Int16, ByVal ParamValue As String)
_MyComm.Parameters.Add(ParamName, paramType, Paramlenght)
_MyComm.Parameters(ParamName).Value = ParamValue
End Sub

Public Sub ExecNonQuerySP(ByVal SPName As String)

Dim ConnectionStr As String = _ConnectionStr
Dim Myconn As New SqlConnection(ConnectionStr)
Dim MyAdapter As New SqlDataAdapter(_MyComm)
_MyComm.CommandType = CommandType.StoredProcedure
_MyComm.CommandText = SPName

Myconn.Open()
_MyComm.Connection = Myconn
Try
_MyComm.ExecuteNonQuery()
Catch ex As Exception
System.Web.HttpContext.Current.Session("DBError") = "True"
System.Web.HttpContext.Current.Session("DBEx") = ex.ToString
Finally
If Myconn.State = ConnectionState.Open Then
Myconn.Close()
End If
End Try
End Sub

Has anyone got any suggestions on how to handle this?

Julia
Oct 28 '08 #1
0 1028

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

Similar topics

1
by: Eirik Tryggeseth | last post by:
During deployment of an application using distributed transactions managed under COM+ on an Oracle 9i RAC database, we encounter situations where the load balancing mechanisms in the RAC result in...
1
by: vpr | last post by:
Hi Guys I have a question re. socketserver and wx. I've written a p2p program using socketserver that's nice and quick. I'd like to give the user a tray applet (part of the p2p service) that...
6
by: user451 | last post by:
As the most Access-savvy person in my office, I have been handed the task of proposing a nationwide expansion of a project that I have developed in Access. A brief overview: Right now, about 25...
47
by: ship | last post by:
Hi We need some advice: We are thinking of upgrading our Access database from Access 2000 to Access 2004. How stable is MS Office 2003? (particularly Access 2003). We are just a small...
3
by: Doug Bell | last post by:
Hi I am putting together a functional specification in preparation for writing a VB Dot Net upgrade an existing Access (VBA) and VB system. It is currently a tiered system with an IBM AS400...
9
by: laststubborn | last post by:
Dear All, We have a big concern in our Database system. We have 2000 transactions daily in our database. We need to replicate some how the database for our fail over setup. I tried transactional...
12
by: Rami | last post by:
I have some requirement for an automated payment system. The system has four machines setup as follows: 1- Two machines have a clustered database. 2- Two machines have a .net business logic...
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: simoncole | last post by:
Hi there Am just about to deploy a new application - one of those 'generic' database types with very little Oracle specific functionality built in. There is no referential integrity, and one...
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
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
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...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.