示例#1
0
        public void TestConnect()
        {
            var connection = new MonetDbConnection();

            Assert.IsTrue(connection.State == ConnectionState.Closed);

            Assert.ThrowsException <InvalidOperationException>(() => connection.Open());

            connection = new MonetDbConnection(TestConnectionString);
            connection.Open();
            Assert.IsTrue(connection.State == ConnectionState.Open);
            Assert.AreEqual(connection.Database, "demo");
            connection.Close();
            Assert.IsTrue(connection.State == ConnectionState.Closed);
            Assert.AreEqual(connection.Database, "demo");

            try
            {
                connection = new MonetDbConnection(TestConnectionString.Replace("ssl=false", "ssl=true"));
                connection.Open();
            }
            catch (MonetDbException ex)
            {
                if (ex.Message.IndexOf("not supported", StringComparison.InvariantCultureIgnoreCase) < 0)
                {
                    throw;
                }
            }
            finally
            {
                connection.Close();
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string connectionString, string commandText)
        {
            int result;

            using (var connection = new MonetDbConnection(connectionString))
            {
                connection.Open();

                using (var command = new MonetDbCommand(connection)
                {
                    CommandText = commandText
                })
                {
                    result = command.ExecuteNonQuery();
                }

                connection.Close();
            }

            return(result);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public static object ExecuteScalar(string connectionString, string commandText)
        {
            object result;

            using (var connection = new MonetDbConnection(connectionString))
            {
                connection.Open();

                using (var command = new MonetDbCommand(connection)
                {
                    CommandText = commandText
                })
                {
                    result = command.ExecuteScalar();
                }

                connection.Close();
            }

            return(result);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public static DataSet ExecuteDataSet(string connectionString, string commandText)
        {
            DataSet ds;

            using (var connection = new MonetDbConnection(connectionString))
            {
                connection.Open();

                using (var command = new MonetDbCommand(connection)
                {
                    CommandText = commandText
                })
                {
                    using (var reader = command.ExecuteReader())
                    {
                        ds = reader.ToDateSet();
                    }
                }

                connection.Close();
            }

            return(ds);
        }