Blog Home  Yalcomania'n�n Yeri Feed your aggregator (RSS 2.0)  
Yalçın Uzun - SQL Dependency
Kişisel Blog
 
 Monday, July 28, 2008

İki de bir unutup durduğum bir şey olduğu için buraya yazayım dedim. En azından her seferinde makale okumak zorunda kalmam.

Aktif hale getirmek için:

ALTER DATABASE Database SET ENABLE_BROKER

C# kodları: (Unutulmaması gereken şey sorguda mutlaka sütun adları kullanılmalı ve from kısmı FQN (dbo.Hede) olmalı)

Global değişkenler:

SqlConnection con = new SqlConnection("server=.;database=Northwind;trusted_connection=true");

SqlCommand com;

SqlDependency dep;

SqlDataAdapter da;

DataTable dt;

 

 

private void Form1_Load(object sender, EventArgs e)

{

   Control.CheckForIllegalCrossThreadCalls = false;

   VeriCek();

}

void VeriCek()

{

   com = new SqlCommand("select ogrenciId,ogrenciAd,OgrenciSoyad from dbo.ogrenciler", con);

   dep = new SqlDependency(com);

   dep.OnChange += new OnChangeEventHandler(dep_OnChange);

   SqlDependency.Start(con.ConnectionString);

   da = new SqlDataAdapter(com);

   dt = new DataTable();

   da.Fill(dt);

   dgVeriler.DataSource = dt;

}

void dep_OnChange(object sender, SqlNotificationEventArgs e)

{

   VeriCek();

}

 

Monday, July 28, 2008 5:29:08 PM (GTB Standard Time, UTC+02:00)  #    Comments [0]    | 
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Copyright © 2009 Yalçın Uzun