문제

In C# client side, we can open SQL connections based on connection string. Connection pool is used to improve the client performance.

We want to monitor how many connections are active and how many are free for use, which is very important to client side health check. Unfortunately, I didn't find any way to get this kind of information. Can any one tell me? Or I have to implement it by myself?

도움이 되었습니까?

해결책

You need to have a wrapper class with count variable to monitor count of connection, on connection.Open() increment by 1 and on connetion.Close() decrement by 1.

다른 팁

public static DataTable GetActiveConnections()
        {
            DataTable objResult = new DataTable();
            try
            {
                using (SqlConnection conection = new SqlConnection("ConnectionSetting"))
                {
                    conection.Open();
                    using (SqlCommand cmd = new SqlCommand("sp_who", conection))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        using (SqlDataAdapter adpter = new SqlDataAdapter())
                        {
                            adpter.SelectCommand = cmd;
                            adpter.Fill(objResult);
                        }
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }

            return objResult;

        }

I haven't check it in c# application but i tested it in SQL Server Management Studio

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top