[RESOLVED] [2005] Connection
Hi all :wave:
If we are using more then one table in my code for saving the data. If both table contain different data then what I want
I want to delete data from first table, if I get error when I am saving then data in the second table.
any property we have directly :confused:
Re: [RESOLVED] [2005] Connection
This is the advance function for connection transaction,commit and the rollback!!
While a transaction is in progress parts of the database will get locked out
from other processes that are trying to access it. This is to ensure the safety of the transaction and other processes that are accessing the database. When you start a transaction perform the queries you need quickly so that the locks don't last long. And do not wait for user input inside a transaction.
tell me if any suggestion!!
VB.NET Code:
#Region "Advance Function for connection rollback And Transaction By Shakti"
':Author ::::Shakti Singh Dulawat
Public Function ExecuteMultipleQuery(ByVal QueryString() As String) As Boolean
Dim myConnection As SqlClient.SqlConnection = Nothing
Dim transaction As System.Data.SqlClient.SqlTransaction
Dim command As DbCommand
myConnection = OpenNewConnection() 'Open The SQL connection Here
command = myConnection.CreateCommand()
Try
transaction = myConnection.BeginTransaction()
command.CommandType = CommandType.Text
command.Transaction = transaction
command.Connection = myConnection
For Each query As String In QueryString
command.CommandText = query
command.ExecuteNonQuery()
Next
transaction.Commit()
Return True
Catch ex As SqlClient.SqlException
Throw New Exception("SQL Exception ", ex)
transaction.Rollback()
Return False
Catch exx As Exception
Throw New Exception("Other ", exx)
transaction.Rollback()
Return False
Finally
myConnection.Close()
command.Dispose()
End Try
End Function
#End Region