VB.Net 2003 - Not Sure whether CONNECTION is CLOSE
Hi there,
I have written this .net script and not sure whether the Connection is Closed after executing the ISQL string.
Could someone please advice me. Thanks
Public Function GFActionRec(ByVal iSql As String) As Integer
'this routine provides generic function for Insert/Delete/Update to table
Try
With adoCmd
.Connection = New SqlConnection(GFGetDataPath)
.Connection.Open()
.CommandText = iSql
GFActionRec = .ExecuteNonQuery()
.Connection.Close()
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
Have a Good Day.
Cheers,
Lennie
[845 byte] By [
Lennie] at [2007-11-11 10:23:55]

# 1 Re: VB.Net 2003 - Not Sure whether CONNECTION is CLOSE
The connection will be closed unless an exception occurs in the lines preceding Connection.Close. In order to ensure that the connection is closed regardless of whether an exception occurs, put Connection.Close in a Finally block:
Public Function GFActionRec(ByVal iSql As String) As Integer
'this routine provides generic function for Insert/Delete/Update to table
Try
With adoCmd
.Connection = New SqlConnection(GFGetDataPath)
.Connection.Open()
.CommandText = iSql
GFActionRec = .ExecuteNonQuery()
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
adoCmd.Connection.Close()
End Try
End Function
# 2 Re: VB.Net 2003 - Not Sure whether CONNECTION is CLOSE
Hi Phil Weber
Yeee...haaaaa............it's working........Thanks Phil.
Come on over to New Zealand,I will buy you a drink.
Lennie at 2007-11-11 20:48:53 >
