使用SqlDependency监测数据库
2011-04-01 17:54
218 查看
SqlDependency提供了:对监测的数据库发生变化通知前台程序的功能。
具体使用如下:
public Form1()
{
InitializeComponent();
SqlDependency.Start(conStr);
NewMethod();
}
string conStr = "data source=.;initial catalog=AssetsManageDB;uid=sa;pwd=****";
private void NewMethod()
{
using (SqlConnection con = new SqlConnection(conStr))
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from TT where flag=1",con);
SqlDependency dependy = new SqlDependency(cmd);
dependy.OnChange += new OnChangeEventHandler(dependy_OnChange);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
MessageBox.Show(dr["message"].ToString());
}
dr.Close();
}
}
void dependy_OnChange(object sender, SqlNotificationEventArgs e)
{
NewMethod();
}
Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=123;User ID=Admin;Data Source=123.mdb
具体使用如下:
public Form1()
{
InitializeComponent();
SqlDependency.Start(conStr);
NewMethod();
}
string conStr = "data source=.;initial catalog=AssetsManageDB;uid=sa;pwd=****";
private void NewMethod()
{
using (SqlConnection con = new SqlConnection(conStr))
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from TT where flag=1",con);
SqlDependency dependy = new SqlDependency(cmd);
dependy.OnChange += new OnChangeEventHandler(dependy_OnChange);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
MessageBox.Show(dr["message"].ToString());
}
dr.Close();
}
}
void dependy_OnChange(object sender, SqlNotificationEventArgs e)
{
NewMethod();
}
Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=123;User ID=Admin;Data Source=123.mdb
相关文章推荐
- 使用SqlDependency时提示当前数据库未启用Service broker
- SQL server 2008R2 中 C#Winfoirm 使用 SqlDependency 机制实现 数据库中某一张表的监视
- 使用SqlDependency后,数据库日志增长过快,并有错误 Service Broker needs to access the master key in the database .
- 使用SqlDependency时提示当前数据库未启用Service broker
- 使用Activity Logging监测Domino数据库的活动状况
- 使用SqlDependency时提示当前数据库未启用Service broker
- 使用SqlDependency时提示当前数据库未启用Service broker
- 使用SqlDependency时提示当前数据库未启用Service broker
- 使用SqlDependency时提示当前数据库未启用Service broker
- miniprofiler的对数据库的监测使用。以nancy,petapoco为例
- sqlDependency提供了这样一种能力:当被监测的数据库中的数据发生变化时,SqlDependency会自动触发OnChange事件来通知应用程序,从而达到让系统自动更新数据(或缓存)的目的.
- 使用ab.exe监测100个并发/100次请求情况下同步/异步访问数据库的性能差异
- 使用SqlDependency时提示当前数据库未启用Service broker
- 使用SqlDependency时提示当前数据库未启用Service broker
- 使用Data Annotations和Fluent API配置数据库的映射
- 使用python链接wamp或者xamp中的数据库
- 轻量级本地数据库SQLite在WinRT的使用
- 数据库游标的使用
- 使用Blast本地数据库获得PSSM特征矩阵
- MySQL数据库 使用MyBatis做持久化时 数据库命名带下划线的列获取不到