private DataSet bindCachedData()
{
string sql = "SELECT * FROM np_pucm_refresh_cal";
constr = "user id=NPUSER;data source=PNPSCAL;password=NPUSER;Min Pool
Size=1;Connection Lifetime=0;Connection Timeout=60;Incr Pool
Size=1;Decr Pool Size=1;";
DataSet ds;
ds = (DataSet)Cache.Get("UserTable");
if (ds ==null)
{
lblMsg.Text = "Data fetched from Table";
using (OracleConnection con = new OracleConnection(constr))
{
con.Open();
using (OracleCommand cmd = new OracleCommand(sql, con))
{
OracleDependency dep = new OracleDependency(cmd);
cmd.Notification.IsNotifiedOnce = false;
dep.OnChange += new OnChangeEventHandler(OnMyNotificaton);
OracleDataAdapter da = new OracleDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
Cache.Insert("UserTable", ds);
}
}
}
else
lblMsg.Text = "Data fetched from Cache";
return ds;
}
public void OnMyNotificaton(object src, OracleNotificationEventArgs arg)
{
DataTable changeDetails = arg.Details;
Cache.Remove("UserTable");
lblMsg.Text = "Data fetched from Table";
}
protected void Timer1_Tick(object sender, EventArgs e)
{
GridView1.DataSource = bindCachedData();
GridView1.DataBind();
}
No comments:
Post a Comment