Each programming language creates instances of ADO Events differently. All the examples that follow create a ConnectComplete event handler.
Visual Basic
Although this example shows only one event handler being created, Visual Basic internally creates all the event handlers in the ConnectionEvent class.
Dim WithEvent connEvent as Connection
Dim conn as New Connection
set connEvent = conn 'Turn on event support.
conn.Open(...)
...
set connEvent = Nothing 'Turn off event support.
...
Private Sub connEvent_ConnectComplete(ByVal err as ADODB.Error, adStatus as ADODB.EventStatus, ByVal conn as ADODB.Connection)
'Check the error object only if adStatus equals adStatusErrorsOccurred.
...
End Sub
Visual C++
???
Visual J++
import com.ms.ado.*;
public class MyClass
{
ConnectionEventHandler handler =
new ConnectionEventHandler(this,"onConnectComplete");
public void onConnectComplete(Object sender,ConnectionEvent e)
{
if (e.adStatus == adStatusErrorsOccurred)
println("Connection failed");
else
println("Connection completed");
return;
}
void main( void )
{
Connection conn = new Connection();
conn.addConnectCompleteHandler(handler); // Turn on event support.
conn.open("DSN=pubs");
conn.close();
conn.removeConnectCompleteHandler(handler); // Turn off event support.
}
}
VBScript
VBScript does not support events.