Exemplo n.º 1
0
 public DbConnection(string connectionString, string providerName)
 {
     if (string.IsNullOrEmpty(providerName))
     {
         throw new ArgumentNullException("providerName");
     }
     if (string.IsNullOrEmpty(connectionString))
     {
         throw new ArgumentNullException("connectionString");
     }
     this.ConnectionString = connectionString;
     this.ProviderName = providerName;
     System.Data.Common.DbProviderFactory factory;
     factory = System.Data.Common.DbProviderFactories.GetFactory(providerName);
     if (factory != null)
     {
         this.connection = factory.CreateConnection();
         this.connection.ConnectionString = connectionString;
         this.connection.Open();
     }
     else
     {
         throw new InvalidOperationException("Failed creating connection.");
     }
 }
        public void Initialize()
        {
            try
            {
                EffortProviderConfiguration.RegisterProvider();
                connection = Effort.DbConnectionFactory.CreateTransient();
                databaseContext = new TestContext(connection);
                objRepo = new CountryRepository(databaseContext);
            }
            catch (Exception ex) {

            }
        }
Exemplo n.º 3
0
 public static void ConnectDB()
 {
     if (DBConn != null)
     {
         if (DBConn.State == ConnectionState.Closed)
         {
             try
             {
                 DBConn.Open();
             }
             catch (Exception ex)
             {
                 //EventLog log = new EventLog();
                 //log.Source = "COPLibrary";
                 //log.WriteEntry(ex.Message , EventLogEntryType.Error);
                 LogEvent(ex.Message, EventLogEntryType.Error);
             }
         }
         return;
     }
     if (WebConfigurationManager.ConnectionStrings["DBType"].ConnectionString == "Oracle")
     {
         DBConn = new OracleConnection();
         DbType = "Oracle";
     }
     //else if (WebConfigurationManager.ConnectionStrings["DBType"].ConnectionString == "MySql")
     //{
     //    DBConn = new MySql.Data.MySqlClient.MySqlConnection();
     //    DbType = "MySql";
     //}
     else
     {
         DBConn = new SqlConnection();
         DbType = "SQLServer";
     }
     if(DBConn.ConnectionString != null)
     DBConn.ConnectionString = WebConfigurationManager.ConnectionStrings["COP"].ConnectionString;
     //if (DBConn.State == ConnectionState.Open)
     //    DBConn.Close();
     try
     {
         DBConn.Open();
     }
     catch (Exception ex)
     {
         //EventLog log = new EventLog();
         //log.Source = "COPLibrary";
         //log.WriteEntry(ex.Message , EventLogEntryType.Error);
         LogEvent(ex.Message, EventLogEntryType.Error);
     }
 }
Exemplo n.º 4
0
        private async Task LiteralReplacementDynamic(IDbConnection conn)
        {
            var args = new DynamicParameters();
            args.Add("id", 123);
            try { await conn.ExecuteAsync("drop table literal2"); } catch { }
            await conn.ExecuteAsync("create table literal2 (id int not null)");
            await conn.ExecuteAsync("insert literal2 (id) values ({=id})", args);

            args = new DynamicParameters();
            args.Add("foo", 123);
            var count = (await conn.QueryAsync<int>("select count(1) from literal2 where id={=foo}", args)).Single();
            count.IsEqualTo(1);
        }
Exemplo n.º 5
0
 private async Task LiteralReplacement(IDbConnection conn)
 {
     try
     {
         await conn.ExecuteAsync("drop table literal1");
     } catch { }
     await conn.ExecuteAsync("create table literal1 (id int not null, foo int not null)");
     await conn.ExecuteAsync("insert literal1 (id,foo) values ({=id}, @foo)", new { id = 123, foo = 456 });
     var rows = new[] { new { id = 1, foo = 2 }, new { id = 3, foo = 4 } };
     await conn.ExecuteAsync("insert literal1 (id,foo) values ({=id}, @foo)", rows);
     var count = (await conn.QueryAsync<int>("select count(1) from literal1 where id={=foo}", new { foo = 123 })).Single();
     count.IsEqualTo(1);
     int sum = (await conn.QueryAsync<int>("select sum(id) + sum(foo) from literal1")).Single();
     sum.IsEqualTo(123 + 456 + 1 + 2 + 3 + 4);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the feature set based on the passed connection
 /// </summary>
 public static FeatureSupport Get(IDbConnection connection)
 {
     string name = connection?.GetType().Name;
     if (string.Equals(name, "npgsqlconnection", StringComparison.OrdinalIgnoreCase)) return postgres;
     return @default;
 }
 internal IDbCommand SetupCommand(IDbConnection cnn, Action<IDbCommand, object> paramReader)
 {
     var cmd = cnn.CreateCommand();
     var init = GetInit(cmd.GetType());
     init?.Invoke(cmd);
     if (Transaction != null)
         cmd.Transaction = Transaction;
     cmd.CommandText = CommandText;
     if (CommandTimeout.HasValue)
     {
         cmd.CommandTimeout = CommandTimeout.Value;
     }
     else if (SqlMapper.Settings.CommandTimeout.HasValue)
     {
         cmd.CommandTimeout = SqlMapper.Settings.CommandTimeout.Value;
     }
     if (CommandType.HasValue)
         cmd.CommandType = CommandType.Value;
     paramReader?.Invoke(cmd, Parameters);
     return cmd;
 }
Exemplo n.º 8
0
 public IdDao(System.Data.Common.DbConnection connection)
 {
     _connection = connection;
 }
Exemplo n.º 9
0
 public IdProvider(ISession session)
 {
     _connection = session.GetPort<System.Data.Common.DbConnection>();
 }
Exemplo n.º 10
0
 public CartDao(ISession session)
 {
     _connection = session.GetPort<System.Data.Common.DbConnection>();
 }
Exemplo n.º 11
0
 protected override void recUpdateInsertDelete(ref System.Data.Common.DbConnection dbConn, out int err)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
 protected override void initialize(ref System.Data.Common.DbConnection dbConn, out int err, out string errMsg)
 {
     err    = 0;
     errMsg = string.Empty;
 }
Exemplo n.º 13
-1
		/// <summary>
		/// 装饰
		/// </summary>
		/// <param name="Connection"></param>
		public DbConnectionHelper(System.Data.Common.DbConnection Connection)
		{
			this._Connection = Connection;
		}
Exemplo n.º 14
-3
 public TestRepository(System.Data.Common.DbConnection connc)
 {
     conn = connc;
 }