问题描述
代码:
公共类JobInfoRepository
{
OracleDependency oracleDependency = null;
public static bool IsNotified = false;
public IEnumerable< jobinfo> GetData()
{
尝试
{
使用(var oracleConnection = new OracleConnection(ConfigurationManager.ConnectionStrings [ WBConnectionString] .ConnectionString))
{
oracleConnection.Open();
使用(OracleCommand oracleCommand = new OracleCommand(@SELECT [CA_ID],[CA_SUMMARY],[CA_DESCRIPTION] FROM [WB_CASES],oracleConnection))
{
//确保命令对象尚未具有
//与之关联的通知对象。
OracleDependency.Port = 1521;
oracleDependency = new OracleDependency( oracleCommand);
oracleCommand.Notification.IsNotifiedOnce = false;
//oracleCommand.AddRowid = true;
oracleDependency.OnChange + = new OnChangeEventHandler(dependency_OnChange);
//OracleDependency.GetOracleDependency(Convert.ToString(ConfigurationManager.ConnectionStrings[\"WBConnectionString\"].ConnectionString));
if( oracleConnection.State == ConnectionState.Closed)
oracleConnection.Open();
List< jobinfo> jobInfoList = new List< jobinfo>();
DataTable _DataTable = new DataTable();
OracleDataAdapter oracleDataAdapter = new OracleDataAdapter(oracleCommand);
oracleDataAdapter.Fill(_DataTable);
for(int i = 0; i< _DataTable.Rows.Count; i ++)
{
JobInfo jobInfo = new JobInfo();
jobInfo.CA_ID = Convert.ToInt32(_DataTable .Rows [i] [0]);
jobInfo.CA_SUMMARY = Convert.ToString(_DataTable.Rows [i] [1]);
jobInfo.CA_DESCRIPTION = Convert .ToString(_DataTable.Rows [i] [2]);
jobInfoList.Add(jobInfo);
jobInfo = null;
}
返回jobInfoList;
}
}
}
catch(Exception ex)
{
抛出ex;
}
}
private void dependency_OnChange(object sender,OracleNotificationEventArgs e)
{
new GetRecordsHub()。ShowRecords();
}
}
公共类JobInfo
{
public int CA_ID {get;组; } $ / $
public string CA_SUMMARY {get;组; }
公共字符串CA_DESCRIPTION {get;组; }
}
问题: Oracledependency对象不调用事件dependency_OnChange。
CODE:
public class JobInfoRepository
{
OracleDependency oracleDependency = null;
public static bool IsNotified = false;
public IEnumerable<jobinfo> GetData()
{
try
{
using (var oracleConnection = new OracleConnection(ConfigurationManager.ConnectionStrings["WBConnectionString"].ConnectionString))
{
oracleConnection.Open();
using (OracleCommand oracleCommand = new OracleCommand(@"SELECT [CA_ID],[CA_SUMMARY],[CA_DESCRIPTION] FROM [WB_CASES]", oracleConnection))
{
// Make sure the command object does not already have
// a notification object associated with it.
OracleDependency.Port = 1521;
oracleDependency = new OracleDependency(oracleCommand);
oracleCommand.Notification.IsNotifiedOnce = false;
//oracleCommand.AddRowid = true;
oracleDependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
//OracleDependency.GetOracleDependency(Convert.ToString(ConfigurationManager.ConnectionStrings["WBConnectionString"].ConnectionString));
if (oracleConnection.State == ConnectionState.Closed)
oracleConnection.Open();
List<jobinfo> jobInfoList = new List<jobinfo>();
DataTable _DataTable = new DataTable();
OracleDataAdapter oracleDataAdapter = new OracleDataAdapter(oracleCommand);
oracleDataAdapter.Fill(_DataTable);
for (int i = 0; i < _DataTable.Rows.Count; i++)
{
JobInfo jobInfo = new JobInfo();
jobInfo.CA_ID = Convert.ToInt32(_DataTable.Rows[i][0]);
jobInfo.CA_SUMMARY = Convert.ToString(_DataTable.Rows[i][1]);
jobInfo.CA_DESCRIPTION = Convert.ToString(_DataTable.Rows[i][2]);
jobInfoList.Add(jobInfo);
jobInfo = null;
}
return jobInfoList;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
private void dependency_OnChange(object sender, OracleNotificationEventArgs e)
{
new GetRecordsHub().ShowRecords();
}
}
public class JobInfo
{
public int CA_ID { get; set; }
public string CA_SUMMARY { get; set; }
public string CA_DESCRIPTION { get; set; }
}
Problem: Oracledependency object is not calling event "dependency_OnChange".
推荐答案
grant change notification to USERID
这篇关于如何使信号器与Oracle一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!