Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top