我想创建一个网站,以便在我的数据库表中的记录被更改,插入或删除时通知我。 所以我启动了一个集线器,注册我的通知监听器(OracleDependency)并更新记录。
var hub = $.connection.oracleNotificationHub;
$("#btnStart").click(function ()
{
$.connection.hub.start().done(function ()
{
$.connection.hub.logging = true;
hub.server.start();
})
});
调用hub.server.start
后,此代码运行:
using (var con = new OracleConnection(ConfigurationManager.ConnectionStrings["CON"].ConnectionString))
{
using (OracleCommand cmd = new OracleCommand("select rowid, root from myTable where id = 1", con))
{
OracleDependency.Port = 1005;
dep = new OracleDependency(cmd, false, 10000, true);
dep.OnChange += new OnChangeEventHandler(OnNotificaton);
con.Open();
cmd.ExecuteNonQuery();
var txn = con.BeginTransaction();
string updateCmdText = "update myTable set root = concat(root, '_') where id = 1";
OracleCommand updateCmd = new OracleCommand(updateCmdText, con);
updateCmd.ExecuteNonQuery();
txn.Commit();
}
}
private void OnNotificaton(object src, OracleNotificationEventArgs arg)
{
DataTable changeDetails = arg.Details;
OracleNotificationInfo info = (OracleNotificationInfo)changeDetails.Rows[0]["Info"];
Write(String.Format("{0}: Data has changed in {1}, QueryId: {2}, Rowid: {3}", DateTime.Now.ToString("HH:mm:ss"), changeDetails.Rows[0]["ResourceName"], changeDetails.Rows[0]["QueryId"], changeDetails.Rows[0]["Rowid"]));
DataChanged = true;
}
此代码适用于控制台应用程序和IIS 8 Express。
我添加了防火墙规则(入站)以允许所有端口1005(TCP)。如果我使用IIS 10运行它,我的应用程序崩溃并且通知事件没有激活。 来自事件查看器的日志:
Faulting application name: w3wp.exe, version: 10.0.10240.16384, timestamp: 0x559f3b1e
Faulting module name: KERNELBASE.dll, version: 10.0.10240.16384, timestamp: 0x559f38c3
Exception code: 0xe0434352 Fault offset: 0x000000000002a1c8 Faulting process id: 0x1030
Faulting application start time: 0x01d102e894da28a5
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\WINDOWS\system32\KERNELBASE.dll
Report Id: 1df08a7c-be69-4b68-b2f2-6d4687db5aa9
Faulting package full name:
Faulting package-relative application ID:
为什么它不适用于完整的IIS?