Esempio n. 1
0
        public void ReleasePooledConnectionsProperly()
        {
            MySqlConnection con = new MySqlConnection(st.GetConnectionString(true));
            MySqlCommand    cmd = new MySqlCommand("show global status like 'aborted_clients'", con);

            con.Open();
            MySqlDataReader r = cmd.ExecuteReader();

            r.Read();
            int numClientsAborted = r.GetInt32(1);

            r.Close();

#if !RT
            AppDomain appDomain = FullTrustSandbox.CreateFullTrustDomain();


            FullTrustSandbox sandbox = (FullTrustSandbox)appDomain.CreateInstanceAndUnwrap(
                typeof(FullTrustSandbox).Assembly.FullName,
                typeof(FullTrustSandbox).FullName);
#endif

            try
            {
                for (int i = 0; i < 200; i++)
                {
#if RT
                    MySqlConnection connection = new MySqlConnection(st.GetPoolingConnectionString());
                    connection.Open();
#else
                    MySqlConnection connection = sandbox.TryOpenConnection(st.GetPoolingConnectionString());
#endif
                    Assert.NotNull(connection);
                    Assert.True(connection.State == ConnectionState.Open);
                    connection.Close();
                }
            }
            finally
            {
#if !RT
                AppDomain.Unload(appDomain);
#endif
            }
            r = cmd.ExecuteReader();
            r.Read();
            int numClientsAborted2 = r.GetInt32(1);
            r.Close();
            Assert.Equal(numClientsAborted, numClientsAborted2);
            con.Close();
        }
        public void MarkConnectionAsClosedProperlyWhenDisposing()
        {
            MySqlConnection con = new MySqlConnection(Connection.ConnectionString);

            con.Open();
            var             cmd = new MySqlCommand("show global status like 'aborted_clients'", con);
            MySqlDataReader r   = cmd.ExecuteReader();

            r.Read();
            int numClientsAborted = r.GetInt32(1);

            r.Close();

            AppDomain        appDomain = FullTrustSandbox.CreateFullTrustDomain();
            FullTrustSandbox sandbox   = (FullTrustSandbox)appDomain.CreateInstanceAndUnwrap(
                typeof(FullTrustSandbox).Assembly.FullName,
                typeof(FullTrustSandbox).FullName);

            try
            {
                MySqlConnection connection = sandbox.TryOpenConnection(Connection.ConnectionString);
                Assert.NotNull(connection);
                Assert.True(connection.State == ConnectionState.Open);
            }
            finally
            {
                AppDomain.Unload(appDomain);
            }

            r = cmd.ExecuteReader();
            r.Read();
            int numClientsAborted2 = r.GetInt32(1);

            r.Close();
            Assert.AreEqual(numClientsAborted, numClientsAborted);
            con.Close();
        }