本文整理汇总了C#中Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.GetInstrumentationEventProvider方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDatabase.GetInstrumentationEventProvider方法的具体用法?C# SqlDatabase.GetInstrumentationEventProvider怎么用?C# SqlDatabase.GetInstrumentationEventProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase
的用法示例。
在下文中一共展示了SqlDatabase.GetInstrumentationEventProvider方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoLotsOfConnectionFailures
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"));
}
}