I am trying get the changed values from the sqlserver using the server_broker feature.
my code is like below
protected void Page_Load(object sender, EventArgs e)
{
GetData2();
}
private void GetData2()
{
List<Masa> lst = new List<Masa>();
using (SqlConnection con = Baglan.Sql)
{
string sql = "SELECT [Id],[Ad],[Durum] FROM [dbo].[Masa]";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
SqlDependency dependency = new SqlDependency(cmd);
dependency.OnChange += new OnChangeEventHandler(dependency_OnDataChangedDelegate);
using (IDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
while (reader.Read())
{
Masa alt = new Masa
{
Ad = reader["Ad"].ToString(),
Id = reader["Id"].ToString(),
Durum = reader["Durum"].ToString()
};
lst.Add(alt);
}
gridMasa.GetStore().DataSource = lst;
gridMasa.GetStore().DataBind();
}
}
}
}
public void dependency_OnDataChangedDelegate(object sender, SqlNotificationEventArgs e)
{ GetData2();
SqlDependency dependency = sender as SqlDependency;
dependency.OnChange -= new OnChangeEventHandler(dependency_OnDataChangedDelegate);
}
when I check the the code via breakpoint which I make some changes on database,It can reach the method called dependency_OnDataChangedDelegate ,but I have no seen changes on my datagrid. where am I doing wrong??
my page source is as below:
<ext:ResourceManager runat="server" ID="mymanager"></ext:ResourceManager>
<ext:GridPanel runat="server" ID="gridMasa" Title="MASALAR" Height="580" Layout="FitLayout" Flex="1"
IDMode="Static">
<Store>
<ext:Store ID="strMasa" runat="server">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="Id" />
<ext:ModelField Name="Ad" />
<ext:ModelField Name="Durum" />
</Fields>
</ext:Model>
</Model>
<Listeners>
<Exception Handler="Ext.Msg.alert('Products - Load failed', operation.getError());" />
</Listeners>
</ext:Store>
</Store>
<ColumnModel ID="ColumnMxodel1" Flex="1" runat="server">
<Columns>
<ext:RowNumbererColumn ID="Column5" runat="server" Text="Id"
>
</ext:RowNumbererColumn>
<ext:Column ID="KisxiId" runat="server" Hidden="true" Text="Id" DataIndex="Id"
Flex="1">
</ext:Column>
<ext:Column ID="Coluxmn2w" runat="server" Text="Masa Adı" Flex="1" Align="Center" DataIndex="Ad">
</ext:Column>
<ext:Column ID="Column8" runat="server" Text="Durum" Flex="1" Align="Center" DataIndex="Durum">
</ext:Column>
<ext:Column ID="Column11" Hidden="true" runat="server" Text="Durum" Flex="1" Align="Center" DataIndex="Durum">
</ext:Column>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="rowSelectioxnModel2" ClientIDMode="Static" runat="server">
<SelectedRows>
<ext:SelectedRow RowIndex="0"></ext:SelectedRow>
</SelectedRows>
</ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>
source code is as below:
Ext.net.ResourceMgr.init({id:"mymanager",aspForm:"form1"}); Ext.onReady(function(){Ext.create("Ext.grid.Panel",{store:{model:Ext.define("App.Model1", {extend: "Ext.data.Model", fields:[{name:"Id"},{name:"Ad"},{name:"Durum"}] }),storeId:"strMasa",autoLoad:true,proxy:{data:[{"Id":"8","Ad":"44448989","Durum":"2"},{"Id":"9","Ad":"MASA 55i","Durum":"1"},{"Id":"12","Ad":"MASA 3","Durum":"1"},{"Id":"44","Ad":"MASA 4","Durum":"1"},{"Id":"45","Ad":"MASA 5","Durum":"1"},{"Id":"46","Ad":"MASA 6","Durum":"-1"},{"Id":"47","Ad":"MASA 7","Durum":"-1"},{"Id":"48","Ad":"MASA 8","Durum":"-1"},{"Id":"49","Ad":"MASA 9","Durum":"1"},{"Id":"51","Ad":"MASA 10","Durum":"2"},{"Id":"52","Ad":"MASA 11","Durum":"-1"},{"Id":"53","Ad":"MASA 12","Durum":"-1"},{"Id":"54","Ad":"MASA 13","Durum":"-1"},{"Id":"55","Ad":"MASA 14","Durum":"-1"},{"Id":"56","Ad":"MASA 15","Durum":"-1"},{"Id":"57","Ad":"MASA 166","Durum":"-1"}], type: 'memory'},listeners:{exception:{fn:function(proxy,response,operation){Ext.Msg.alert('Products - Load failed', operation.getError());}}}},id:"gridMasa",height:580,renderTo:"App.gridMasa_Container",flex:1,layout:"fit",title:"MASALAR",columns:{id:"ColumnMxodel1",flex:1,items:[{id:"Column5",xtype:"rownumberer",text:"Id"},{id:"KisxiId",hidden:true,flex:1,dataIndex:"Id",text:"Id"},{id:"Coluxmn2w",flex:1,align:"center",dataIndex:"Ad",text:"Masa Adı"},{id:"Column8",flex:1,align:"center",dataIndex:"Durum",text:"Durum"},{id:"Column11",hidden:true,flex:1,align:"center",dataIndex:"Durum",text:"Durum"}]},selModel:window.App.rowSelectioxnModel2=Ext.create("Ext.selection.RowModel",{proxyId:"rowSelectioxnModel2",selType:"rowmodel",selectedData:[{rowIndex:0}]})});});
update
this is how enable database(sql server express 2012) which triger every changes happened database.
alter database [Your database name here] set enable_broker with rollback immediate
select name, is_broker_enabled from sys.databases