JaedenRuiner
Well-known member
- Joined
- Aug 13, 2007
- Messages
- 340
- Programming Experience
- 10+
On my form (AdminForm) I have an Object declared "WithEvents" which listens for a DB Connection Event within my internal class. During the Disconnect/Reconnect methods that attach my wrapper class to a database connection, a specific event is triggering only half of the time.
The Logon method (a global method that opens the Login form and executes the connection) receives this object from the AdminForm as a ByRef parameter, allowing me to Create the object and open the connection, at which point all the other event handling is working except this one event.
This is very quick pseudo-code, but it is clear enough. The AdminFrom execute the ReConnect() method, which calls the DoLogon Method in the App Events Global file. The DoLogon method gets the login info from the login form and creates the new DBWrapper class, and then executes teh DBWrapper.Connect. When the Connect method fires it opens the connection which calls the SqlConnection.StateChange Event (this all fires as i've stepped through it), however when it comes to the line in the StateChange event handler that raises the DBWrapper.ConnectionEvent Event, that event does not trigger back to the AdminForm ConnectionEvent handler for the Rexcon object. As I am passing this all via ByRef and reference passing, I would expect the with events to maintain throughout.
Does the "New DBWrapper()" need to take place before the DoLogon event is called to connect?
thanks
The Logon method (a global method that opens the Login form and executes the connection) receives this object from the AdminForm as a ByRef parameter, allowing me to Create the object and open the connection, at which point all the other event handling is working except this one event.
VB.NET:
[U]AdminForm.vb[/U]
private WithEvents _RexCon as DBWrapper
public sub _RexCon_ConnectionEvent(...) handles _RexCon.ConnectionEvent
'code
end sub
public Sub Reconnect()
if not My.Application.DoLogon(_RexCon) then
Application.Exit
end if
end sub
[U]ApplicationEvents.vb[/U]
public Sub DoLogon(byref RexCon as DBWrapper)
if LoginForm.ShowDialog(...) then
RexCon = new DBWrapper(...)
RexCon.Connect(...)
end if
end sub
[U]DBWrapper[/U]
private withevents _conn as SqlConnection
public sub Connect(...)
_conn.Open()
end sub
public sub _conn_StateChange(...) handles _conn.StateChange
RaiseEvent ConnectionEvent(...)
end sub
This is very quick pseudo-code, but it is clear enough. The AdminFrom execute the ReConnect() method, which calls the DoLogon Method in the App Events Global file. The DoLogon method gets the login info from the login form and creates the new DBWrapper class, and then executes teh DBWrapper.Connect. When the Connect method fires it opens the connection which calls the SqlConnection.StateChange Event (this all fires as i've stepped through it), however when it comes to the line in the StateChange event handler that raises the DBWrapper.ConnectionEvent Event, that event does not trigger back to the AdminForm ConnectionEvent handler for the Rexcon object. As I am passing this all via ByRef and reference passing, I would expect the with events to maintain throughout.
Does the "New DBWrapper()" need to take place before the DoLogon event is called to connect?
thanks