JaedenRuiner
Well-known member
- Joined
- Aug 13, 2007
- Messages
- 340
- Programming Experience
- 10+
it appears that the byref flag for a parameter is more like a: "Assignment on exit" than a "Here's my Address", is that true?
Reason:
Anyway around this? I have to trap when my _conn connection opened/closed, but through the ByRef Passing to the SqlConnectionMgr it is not assigned to a value until after i exit GetConnection().
Thanks
Reason:
VB.NET:
[u]SqlConnectionMgr[/u]
Public Shadows Function Add(ByVal ConnectionString As String) As SqlConnection
Dim con As New SqlConnection(ConnectionString)
MyBase.Add(con)
Return con
End Function
Protected Overrides Sub InsertItem(ByVal index As Integer, _
ByVal item As System.Data.SqlClient.SqlConnection)
AddHandler item.StateChange, AddressOf Me.Connection_StateChange
AddHandler item.Disposed, AddressOf Me.Connection_Disposed
MyBase.InsertItem(index, item)
End Sub
Public Function GetConnection(ByRef Connection As SqlClient.SqlConnection, _
Optional ByVal TrapException As Boolean = True) As Boolean
If CanConnect Then
Try
Connection = Add(_connstr.ConnectionString)
Connection.Open()
If Connection.State = ConnectionState.Open Then
_state = MgrConnectionState.Connected
Return True
End If
Catch ex As Exception When TrapException
_ex = ex
If ex.Message.ToLower.IndexOf("login failed").Between(0, 10) Then
_state = MgrConnectionState.Failed
Else : _state = MgrConnectionState.NoConnection
End If
End Try
If Connection IsNot Nothing Then Connection.Dispose()
Else : _state = MgrConnectionState.InvalidParameter
End If
Connection = Nothing
Return False
End Function
Private Sub Connection_StateChange(ByVal sender As Object, _
ByVal e As System.Data.StateChangeEventArgs) _
Handles con.StateChange
RaiseEvent ConnectionEvent(Me, New MgrStateChangeEventArgs(sender, e))
If e.CurrentState = ConnectionState.Closed Then
DirectCast(sender, SqlConnection).Dispose()
End If
End Sub
VB.NET:
Public Function Connect(ByRef Login As LoginStruct) As MgrConnectionState
'i execute this
If ([b]_connmgr.GetConnection(_conn)[/b]) AndAlso (_conn IsNot Nothing) Then
_manager.SetConnection(_conn)
_dsFilled = False
End If
Return _connmgr.Status
End Function
Private Sub _connmgr_ConnectionEvent(ByVal sender As Object, _
ByVal e As FlufLib.MgrStateChangeEventArgs) _
Handles _connmgr.ConnectionEvent
[b]'This never works because at this point of execution, _conn is still nothing[/b]
If e.Connection.Equals(_conn) Then
RaiseEvent ConnectionEvent(Me, New ConnectionEventArgs(e))
End If
End Sub
[b]'This Event Never Fires on Connection.Open().[/b]
Private Sub _conn_StateChange(ByVal sender As Object, _
ByVal e As System.Data.StateChangeEventArgs) _
Handles _conn.StateChange
RaiseEvent ConnectionEvent(Me, New ConnectionEventArgs(e.CurrentState, e.OriginalState, sender))
End Sub
Anyway around this? I have to trap when my _conn connection opened/closed, but through the ByRef Passing to the SqlConnectionMgr it is not assigned to a value until after i exit GetConnection().
Thanks