using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace SqlCacheDependency
{
class Program
{
public static string connString = "server=localhost;uid=sa;pwd=123456;database=dbTest";
public static Dictionary<int, string> dt;
public static Stack<SqlDepState> ss = new Stack<SqlDepState>();
public static void GenerateMonitor()
{
SqlDependency.Start(connString);
dt = new Dictionary<int, string>();
dt.Add(2, "select id,name from dbo.test where id<>4 order by id desc");
dt.Add(8, "select id,name from dbo.test where id<>4 order by id desc");
dt.Add(3, "select id,name from dbo.test where id<>4 order by id desc");
dt.Add(5, "select id,name from dbo.test where id<>4 order by id desc");
int i = 0;
SqlDepState[] sess = new SqlDepState[dt.Count];
foreach (KeyValuePair<int, string> item in dt)
{
sess[i] = new SqlDepState(item.Key, item.Value);
sess[i].RecordChanged += delegate(object sender)
{
Console.WriteLine(((SqlDepState)sender).ID.ToString());
};
i++;
}
}
}
public delegate void RecordChangeHandler(object sender);
public class SqlDepState
{
public int ID;
public string commText;
public event RecordChangeHandler RecordChanged;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using zhaotest1.BusinessLayer;
namespace SqlCacheDependency
{
class Program
{
public static string connString = "server=localhost;uid=sa;pwd=123456;database=dbTest";
public static Dictionary<int, string> dt;
public static Stack<SqlDepState> ss = new Stack<SqlDepState>();
public static void GenerateMonitor()
{
SqlDependency.Start(connString);
SqlCommandTextFactory sqlCommandTextFactory = new SqlCommandTextFactory();
List<SqlCommandText> ss = sqlCommandTextFactory.GetAll();
int i = 0;
SqlDepState[] sess = new SqlDepState[ss.Count];
ss.ForEach(
#region 委托
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace SqlCacheDependency
{
class Program
{
static string connString = "server=localhost;uid=sa;pwd=123456;database=dbTest";
static void Main(string[] args)
{
intSql(-1);
Console.ReadLine();
}
public static void intSql(int i)
{
SqlDependency.Start(connString);
Dictionary<int, string> dt = new Dictionary<int, string>();
dt.Add(1, "select id,name from dbo.test where id<>4 order by id desc");
dt.Add(2, "select id,name from dbo.test where id<>4 order by id desc");
dt.Add(3, "select id,name from dbo.test where id<>4 order by id desc");
dt.Add(4, "select id,name from dbo.test where id<>4 order by id desc");
foreach (KeyValuePair<int, string> item in dt)
{
if (i != -1)
{
if (i == item.Key)
{
init(item.Key, item.Value);
}
}
else
{
init(item.Key, item.Value);
}
}
}
private static void init(int key,string value)
{
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand command = new SqlCommand("select id,name from dbo.test where id<>4 order by id desc", conn);
command.Notification = null;
SqlDependency d = new SqlDependency(command);
conn.Open();
SqlDataReader ProductsDr = command.ExecuteReader();
new SqlDepState(key, value, d);
}
}
}
class SqlDepState
{
public SqlDependency dep;
public int ID;
public string commText;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace SqlCacheDependency
{
class Program
{
static string connString = "server=localhost;uid=sa;pwd=123456;database=dbTest";
static void Main(string[] args)
{
intSql(-1);
Console.ReadLine();
}
public static void intSql(int i)
{
SqlDependency.Start(connString);
Dictionary<int, string> dt = new Dictionary<int, string>();
dt.Add(1, "select id,name from dbo.test where id<>4 order by id desc");
dt.Add(2, "select id,name from dbo.test where id<>4 order by id desc");
dt.Add(3, "select id,name from dbo.test where id<>4 order by id desc");
dt.Add(4, "select id,name from dbo.test where id<>4 order by id desc");
foreach (KeyValuePair<int, string> item in dt)
{
if (i != -1)
{
if (i == item.Key)
{
init(item.Key, item.Value);
}
}
else
{
init(item.Key, item.Value);
}
}
}
private static void init(int key,string value)
{
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand command = new SqlCommand("select id,name from dbo.test where id<>4 order by id desc", conn);
command.Notification = null;
SqlDependency d = new SqlDependency(command);
conn.Open();
SqlDataReader ProductsDr = command.ExecuteReader();
new SqlDepState(key, value, d);
}
}
}
class SqlDepState
{
public SqlDependency dep;
public int ID;
public string commText;