Is there a way to use DBMS_Alert to notify a Winform application of a database change

I am trying to get a winform application to update the embedded browser when changing the database using Oracle 10g. The only problem is that I am not allowed to use the database change notification. I am curious if anyone has a way to use the built-in DBMS_Alert package and there were some actions with the winform application when changing the database.

Thanks Andrew

+1
source share
3 answers

, . , , , DBMS_Alert. :

OracleConnection conn = new OracleConnection(ConnectionString);
conn.Open();
OracleCommand cmd = new OracleCommand("DECLARE\n" + 
                                        "MESSAGE VARCHAR2(1800) := null;\n" +
                                      "STATUS INTEGER;\n" +
                                      "BEGIN\n" +
                                        "DBMS_ALERT.REGISTER('ALERT');\n" +
                                        "DBMS_ALERT.WAITONE('ALERT', MESSAGE, STATUS);\n" + 
                                        "DBMS_ALERT.REMOVE('ALERT');\n" + 
                                      "END;", conn);

cmd.ExecuteNonQuery();
wbMain.Refresh();
conn.Dispose();

, . , , , .

+2

...

ODP, Oracle Advanced Queuing/Streams .

.

, , , PO # !

, , , .

+2

Better to use without a timer. Below is sample code with background thread

Here is a snippet of code

privateThread DBMSAlertThread;

private void DBMSAlert(bool Register)
        {
            try
            {
                string sSql;
                if (Register)
                   sSql = "call dbms_alert.register('XYZ')";
                else
                   sSql = "call dbms_alert.remove('XYZ')";
                dbmsAlert = new OracleCommand();
                dbmsAlert.CommandText = sSql;
                dbmsAlert.ExecuteNonQuery();  

                if (Register) //start the background thread
               {
                   DBMSAlertThread = new Thread(AlertEvent);
                   DBMSAlertThread.IsBackground = true;
                   DBMSAlertThread.Start();
               }
            }
            catch (Exception LclExp)
            {
                //Show error or capture in eventlog
            }            
        }

private void AlertEvent(object sender) 
{
    while (true)
    {
        string Message = "";
        int Status = -1;
        bool bStatus;
        OracleParameter param;
        try
        {
            OracleCommand dbmsAlert = new OracleCommand();
            dbmsAlertScan.SQL.Add("call dbms_alert.WaitOne('XYZ', :Message, :Status, 0)"); //Last parameter indicate wait time
            param = new OracleParameter("Message", OracleDbType.Varchar2, ParameterDirection.Output);
            dbmsAlert.Parameters.Add(param); 
            param = new OracleParameter("Status", OracleDbType.Varchar2, ParameterDirection.Output);
            dbmsAlert.Parameters.Add(param); 
            OracleParameter.ExceuteNonQuery();

            Message = dbmsAlert.Parameters["Message"].Value.ToString();
            bStatus = int.TryParse(dbmsAlert.Parameters["Status"].Value.ToString(), out Status);

            if (Status == 0) //0 = Alert Received, 1 = Timed out
            {
                //notify or do ur stuff
            }
        }
        catch (Exception Exp)
        {
            //raise an error
        }
    }
}
+1
source

All Articles