Conceived this procedure in Visual studio 2008, runs in a separate thread:
void Run() { string oradb = "Data Source=" + Alias.Text + ";" + "User Id=" + Login.Text + ";" + "Password=" + Password.Text + ";"; foring = 0; //--- OracleCommand cmd=null; OracleDataReader dr=null; string str; var ink = FindWindow(null, "Alert locks");//Получаем дескриптор окна do { try { conn = new OracleConnection(oradb); // C# conn.Open(); cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT COUNT(id1) d FROM V$LOCK WHERE request > 0"; cmd.CommandType = CommandType.Text; dr = cmd.ExecuteReader(); dr.Read(); str = dr["d"].ToString(); if ((str != "0") && (foring == 0)) { SetWindowPos(ink, (IntPtr)HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);//Включает свойство TOPMOST - Дескриптору окну MessageBox(ink, "ATTENTION!!! LOCKS FOUND!!!", "Alert locks message", MB_ICONSTOP | MB_TOPMOST); SetWindowPos(ink, (IntPtr)HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);//Отключает свойство TOPMOST - Дескриптору окну Thread.Sleep(300); }; } catch (OracleException ex) // catches only Oracle errors { switch (ex.Number) { case 03113: MessageBox(ink, "Lost connection to the database.", "Alert locks message", 0); break; default: MessageBox(ink, "Database error: " + ex.Message.ToString(), "Alert locks message", 0); break; } } catch (Exception ex) // catches any error not previously caught { MessageBox(ink, ex.Message.ToString(), "Alert locks message", 0); } finally { dr.Dispose(); cmd.Dispose(); conn.Dispose(); } } while (foring == 0); }
I decided to constantly monitor the request (I know that you can write differently, this is a test version). As soon as there is a result, a message will be displayed, after which it is closed, monitoring will continue (you can stop it only through a button on the form so that the cycle is not infinite). Actually, after checking what will happen when a session is killed, I found that after the exception was triggered and the next iterations passed, the session turned into 5 sessions (only the sides are different). The question is why and how to get rid of it?
Ps I know about the work of the provider with the pool, and why Open and Dispose and how they can be replaced, but since I am studying recently, maybe I didn’t take something into account -_-