public void DoLotsOfConnectionFailures() { int numberOfEvents = 50; using (WmiEventWatcher eventListener = new WmiEventWatcher(numberOfEvents)) { SqlDatabase db = new SqlDatabase("BadConnectionString"); DataInstrumentationListener listener = new DataInstrumentationListener("foo", true, true, true); DataInstrumentationListenerBinder binder = new DataInstrumentationListenerBinder(); binder.Bind(db.GetInstrumentationEventProvider(), listener); for (int i = 0; i < numberOfEvents; i++) { try { db.ExecuteScalar(CommandType.Text, "Select count(*) from Region"); } catch { } } eventListener.WaitForEvents(); Assert.AreEqual(numberOfEvents, eventListener.EventsReceived.Count); Assert.AreEqual("ConnectionFailedEvent", eventListener.EventsReceived[0].ClassPath.ClassName); Assert.AreEqual("foo", eventListener.EventsReceived[0].GetPropertyValue("InstanceName")); Assert.AreEqual(db.ConnectionStringWithoutCredentials, eventListener.EventsReceived[0].GetPropertyValue("ConnectionString")); } }