I have a separate class for Business Logic in App_Code :
These are the two code blocks:
Public Shared Function createNewAccID(ByVal FBAccountID As String, ByVal FirstName As String, ByVal LastName As String, ByVal Email As String, ByVal UserName As String, ByVal Gender As String) As Object
Dim db As SqlDatabase = Connection.connection
Try
Using cmd As SqlCommand = db.GetSqlStringCommand("INSERT INTO UserAccounts (AccountID,FBID,TwitterID,FirstName,LastName,Email,EmailVerified,UserName,Password,Gender,CreateDate,Points,CurrentBadge,Abused,isActive,AccountTypeID) VALUES ('" & BLL.getNewAccID & "',@FBID,'',@FirstName,@LastName,@Email,'" & True & "',@UserName,'','" & Gender & "','" & Date.Now.Date & "'," & 5 & ",'Silver'," & 0 & ",'" & True & "'," & 1 & ")")
db.AddInParameter(cmd, "FBID", SqlDbType.VarChar, FBAccountID)
db.AddInParameter(cmd, "FirstName", SqlDbType.VarChar, FirstName)
db.AddInParameter(cmd, "LastName", SqlDbType.VarChar, LastName)
db.AddInParameter(cmd, "Email", SqlDbType.VarChar, Email)
db.AddInParameter(cmd, "UserName", SqlDbType.VarChar, "")
db.ExecuteNonQuery(cmd)
End Using
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Shared Function insertIntoMandatorySteps(ByVal FBAccountID As String) As Object
Dim db As SqlDatabase = Connection.connection
Try
Dim accID As Integer = getAccIDFromDB(FBAccountID)
Using cmd As SqlCommand = db.GetSqlStringCommand("INSERT INTO MandatorySteps (AccountID,NextStepID,NextStepName,AllStepsCompleted) VALUES ('" & accID & "',0,'Interests','" & False & "')")
db.ExecuteNonQuery(cmd)
End Using
Return True
Catch ex As Exception
Return False
End Try
End Function
I call these functions from my aspx.vb page, when i call both the functions in a sinle button click or sub , i want to use connection based transaction. How do i apply transaction to this functions.
I know how to use transactions, i want to know is there any way i can apply transaction when calling the functions (when implementing multiple inserts).
Just a scenario:
1. I am calling both the functions : Here i want that if both the functions execute properly then commit.
2. I am calling only one function i.e function 1 or function 2 : Here i want the transaction to be applied to that particular function only.
You see the functions are in business logic layer and i call the functons from different places, so i need the flexibility to pass the transaction parameter depending upon how many functions i want to execute in a single connection.