コード例 #1
0
        public void ClientFactory()
        {
            DbProviderFactory         f  = new MySqlClientFactory();
            DbConnection              c  = f.CreateConnection();
            DbConnectionStringBuilder cb = f.CreateConnectionStringBuilder();

            cb.ConnectionString = GetConnectionString(true);
            c.ConnectionString  = cb.ConnectionString;
            c.Open();

            DbCommand cmd = f.CreateCommand();

            cmd.Connection  = c;
            cmd.CommandText = "SHOW TABLES FROM test";
            cmd.CommandType = CommandType.Text;
            DbDataReader reader = null;

            try
            {
                reader = cmd.ExecuteReader();
                reader.Read();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
コード例 #2
0
        public void ClientFactory()
        {
            DbProviderFactory f = new MySqlClientFactory();

            using (DbConnection c = f.CreateConnection())
            {
                DbConnectionStringBuilder cb = f.CreateConnectionStringBuilder();
                cb.ConnectionString = st.GetConnectionString(true);
                c.ConnectionString  = cb.ConnectionString;
                c.Open();

                DbCommand cmd = f.CreateCommand();
                cmd.Connection  = c;
                cmd.CommandText = "SELECT 1";
                cmd.CommandType = CommandType.Text;
                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    reader.Read();
                }
            }
        }