当前位置: 首页>>代码示例>>C#>>正文


C# Common.DbConnection类代码示例

本文整理汇总了C#中System.Data.Common.DbConnection的典型用法代码示例。如果您正苦于以下问题:C# DbConnection类的具体用法?C# DbConnection怎么用?C# DbConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DbConnection类属于System.Data.Common命名空间,在下文中一共展示了DbConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ForSpecific

 public string[] ForSpecific(DbConnection connection,
     string collectionName,
     string value,
     string restrictionName)
 {
     return GetSchemaRestrictions(connection, collectionName, value, restrictionName);
 }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:7,代码来源:SchemaRestrictions.cs

示例2: DiscoverSpParameterSet

        /// <summary>
        /// Resolve at run time the appropriate set of DbParameters for a stored procedure
        /// </summary>
        /// <param name="transaction">A valid SqlTransaction object</param>
        /// <param name="connection">A valid SqlConnection object</param>
        /// <param name="storedProcedureName">The name of the stored procedure</param>
        /// <param name="includeReturnValueParameter">Whether or not to include their return value parameter</param>
        /// <returns>The parameter array discovered.</returns>
        private static IList<SqlParameter> DiscoverSpParameterSet(DbTransaction transaction, DbConnection connection, string storedProcedureName, bool includeReturnValueParameter)
        {
            using (SqlCommand cmd = new SqlCommand(storedProcedureName, connection as SqlConnection))
            {
                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                }

                cmd.CommandType = CommandType.StoredProcedure;
                if (transaction != null)
                {
                    cmd.Transaction = transaction as SqlTransaction;
                }

                SqlCommandBuilder.DeriveParameters(cmd);

                if (!includeReturnValueParameter)
                {
                    cmd.Parameters.RemoveAt(0);
                }

                SqlParameter[] discoveredParameters = new SqlParameter[cmd.Parameters.Count];

                cmd.Parameters.CopyTo(discoveredParameters, 0);

                return discoveredParameters;
            }
        }
开发者ID:jawn,项目名称:SqlHelper,代码行数:37,代码来源:ParameterCache.cs

示例3: OnCommitted

 public void OnCommitted(DbConnection connection)
 {
     _transactionEventTimeline.WriteTimelineMessage();
     _transactionLifetimeTimeline.WriteTimelineMessage(true);
     _transactionEventTimeline    = null;
     _transactionLifetimeTimeline = null;
 }
开发者ID:ttakahari,项目名称:AdoNetProfiler,代码行数:7,代码来源:GlimpseAdoNetProfiler.cs

示例4: CreateCommand

 public override DbCommand CreateCommand(DbConnection conn)
 {
     var cmd = conn.CreateCommand();
     var pi = cmd.GetType().GetProperty("BindByName");
     if (pi != null) pi.SetValue(cmd, true, null);
     return cmd;
 }
开发者ID:BrettBailey,项目名称:nginn-messagebus,代码行数:7,代码来源:SqlAbstractions.cs

示例5: GetDbTypes

        /// <summary>Gets the db types for the SQL CE provider.</summary>
        /// <param name="connection">The connection (not required).</param>
        /// <returns></returns>
        public override Dictionary<string, DbModelType> GetDbTypes(DbConnection connection)
        {
            Dictionary<string, DbModelType> dbTypes = new Dictionary<string, DbModelType>();
            string dataTypesSql = "SELECT * FROM information_schema.provider_types";
            using (var cmd = connection.CreateCommand())
            {
                cmd.CommandText = dataTypesSql;
                cmd.CommandType = CommandType.Text;
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string typeName = (string)reader["TYPE_NAME"];
                        int columnSize = Convert.ToInt32(reader["COLUMN_SIZE"]);
                        DbModelType dbType = new DbModelType(typeName, columnSize);

                        dbType.CreateParameters = Convert.ToString(reader["CREATE_PARAMS"]);
                        dbType.LiteralPrefix = Convert.ToString(reader["LITERAL_PREFIX"]);
                        dbType.LiteralSuffix = Convert.ToString(reader["LITERAL_SUFFIX"]);
                        dbType.ProviderDbType = Convert.ToString(reader["DATA_TYPE"]);

                        FixCreateFormat(dbType);
                        FixMaxLengths(dbType);
                        AssignSystemTypes(dbType);

                        dbTypes.Add(typeName, dbType);
                    }
                }
            }

            return dbTypes;
        }
开发者ID:ClusterReply,项目名称:minisqlquery,代码行数:35,代码来源:SqlCeSchemaService.cs

示例6: GetCommandWrap

 protected internal virtual IDbCommandWrap GetCommandWrap(IStatementSetting statement)
 {
     DbConnection connection;
     var closeConnectionOnCommandDisposed = true;
     if (this.IsInTransaction) {
         if (this.transaction == null) {
             lock (this.lockTransaction) {
                 if (this.transaction == null) {
                     connection = this.GetConnection(statement);
                     connection.Open();
                     if(this.DataService.Debug) {
                         LogService.WriteLog(this, LogLevel.DEBUG, "Connection open with transaction:" + connection.GetHashCode());
                     }
                     this.transaction = connection.BeginTransaction();
                 }
             }
         }
         connection = this.Transaction.Connection;
         closeConnectionOnCommandDisposed = false;
     } else {
         connection = this.GetConnection(statement);
         connection.Open();
         if(this.DataService.Debug) {
             LogService.WriteLog(this, LogLevel.DEBUG, "Connection open without transaction:" + connection.GetHashCode());
         }
     }
     var command = connection.CreateCommand();
     command.Transaction = this.Transaction;
     return new DbCommandWrap(command, closeConnectionOnCommandDisposed);
 }
开发者ID:mer2,项目名称:devfx,代码行数:30,代码来源:DataSessionBase.cs

示例7: Exec

 protected static void Exec(DbConnection conn, string sql)
 {
     using(var cmd = conn.CreateCommand()) {
         cmd.CommandText = sql;
         cmd.ExecuteNonQuery();
     }
 }
开发者ID:edgarborja,项目名称:LimeBean,代码行数:7,代码来源:ConnectionFixture.cs

示例8: CreateCommand

 internal static DbCommand CreateCommand(DbConnection conn = null)
 {
     var factory = GetFactory();
     var result = factory.CreateCommand();
     result.Connection = conn;
     return result;
 }
开发者ID:Anupam-,项目名称:Ilaro.Admin,代码行数:7,代码来源:DB.cs

示例9: SharedConnectionInfo

        /// <summary>
        /// Instantiate an opened connection enlisted to the Transaction
        /// if promotable is false, the Transaction wraps a local 
        /// transaction inside and can never be promoted
        /// </summary>
        /// <param name="dbResourceAllocator"></param>
        /// <param name="transaction"></param>
        /// <param name="wantPromotable"></param>
        internal SharedConnectionInfo(
            DbResourceAllocator dbResourceAllocator,
            Transaction transaction,
            bool wantPromotable,
            ManualResetEvent handle)
        {
            Debug.Assert((transaction != null), "Null Transaction!");

            if (null == handle)
                throw new ArgumentNullException("handle");

            this.handle = handle;

            if (wantPromotable)
            {
                // Enlist a newly opened connection to this regular Transaction
                this.connection = dbResourceAllocator.OpenNewConnection();
                this.connection.EnlistTransaction(transaction);
            }
            else
            {
                // Make this transaction no longer promotable by attaching our 
                // IPromotableSinglePhaseNotification implementation (LocalTranscaction)
                // and track the DbConnection and DbTransaction associated with the LocalTranscaction
                LocalTransaction localTransaction = new LocalTransaction(dbResourceAllocator, handle);
                transaction.EnlistPromotableSinglePhase(localTransaction);
                this.connection = localTransaction.Connection;
                this.localTransaction = localTransaction.Transaction;
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:38,代码来源:SharedConnectionInfo.cs

示例10: Table

    internal Table(string tableName, DbConnection connection, TableDesignerDoc owner)
    {
      _owner = owner;
      _oldname = tableName;
      _connection = connection;
      _name = tableName;
      _owner.Name = _name;
      _catalog = _connection.Database; // main

      ReloadDefinition();

      if (_key == null) _key = new PrimaryKey(_connection, this, null);

      if (_exists)
      {
        using (DataTable tbl = connection.GetSchema("ForeignKeys", new string[] { Catalog, null, Name }))
        {
          foreach (DataRow row in tbl.Rows)
          {
            _fkeys.Add(new ForeignKey(connection, this, row));
            _oldfkeys.Add(new ForeignKey(connection, this, row));
          }
        }
      }

      using (DataTable tbl = connection.GetSchema("Columns", new string[] { Catalog, null, Name }))
      {
        foreach (DataRow row in tbl.Rows)
        {
          _columns.Add(new Column(row, this));
        }
      }
    }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:33,代码来源:Table.cs

示例11: SQLCODEC

 public SQLCODEC(string sql, int inputSize, int idealSize, string connectString)
 {
     while (true)
     {
         this._x7e648b416c264559 = inputSize;
         this._x08b9e0820ab2b457 = idealSize;
         do
         {
             this._x7316af229433e69e = new OleDbConnection(connectString);
             this._x7316af229433e69e.Open();
             this._xd1d7cdb50796b29b = this._x7316af229433e69e.CreateCommand();
             if ((((uint) inputSize) - ((uint) inputSize)) <= uint.MaxValue)
             {
                 this._xd1d7cdb50796b29b.CommandText = sql;
                 this._xd1d7cdb50796b29b.Prepare();
             }
             this._xd1d7cdb50796b29b.Connection = this._x7316af229433e69e;
             if ((((uint) idealSize) - ((uint) idealSize)) >= 0)
             {
                 return;
             }
         }
         while ((((uint) idealSize) + ((uint) inputSize)) > uint.MaxValue);
     }
 }
开发者ID:neismit,项目名称:emds,代码行数:25,代码来源:SQLCODEC.cs

示例12: Roles_CreateRole

		public static int Roles_CreateRole (DbConnection connection, string applicationName, string rolename)
		{
			string appId = (string) DerbyApplicationsHelper.Applications_CreateApplication (connection, applicationName);
			if (appId == null)
				return 1;

			string querySelect = "SELECT RoleName FROM aspnet_Roles WHERE ApplicationId = ? AND LoweredRoleName = ?";
			OleDbCommand cmdSelect = new OleDbCommand (querySelect, (OleDbConnection) connection);
			AddParameter (cmdSelect, "ApplicationId", appId);
			AddParameter (cmdSelect, "LoweredRoleName", rolename.ToLowerInvariant ());

			using (OleDbDataReader reader = cmdSelect.ExecuteReader ()) {
				if (reader.Read ())
					return 2; // role already exists
			}

			string queryInsert = "INSERT INTO aspnet_Roles (ApplicationId, RoleId, RoleName, LoweredRoleName) VALUES (?, ?, ?, ?)";
			OleDbCommand cmdInsert = new OleDbCommand (queryInsert, (OleDbConnection) connection);
			AddParameter (cmdInsert, "ApplicationId", appId);
			AddParameter (cmdInsert, "RoleId", Guid.NewGuid ().ToString ());
			AddParameter (cmdInsert, "RoleName", rolename);
			AddParameter (cmdInsert, "LoweredRoleName", rolename.ToLowerInvariant ());
			cmdInsert.ExecuteNonQuery ();

			return 0;
		}
开发者ID:runefs,项目名称:Marvin,代码行数:26,代码来源:DerbyRolesHelper.cs

示例13: Roles_DeleteRole

		public static int Roles_DeleteRole (DbConnection connection, string applicationName, string rolename, bool deleteOnlyIfRoleIsEmpty)
		{
			string appId = DerbyApplicationsHelper.GetApplicationId (connection, applicationName);
			if (appId == null)
				return 1;

			string roleId = GetRoleId (connection, appId, rolename);
			if (roleId == null)
				return 2;

			if (deleteOnlyIfRoleIsEmpty) {
				string querySelect = "SELECT RoleId FROM aspnet_UsersInRoles WHERE RoleId = ?";
				OleDbCommand cmdSelect = new OleDbCommand (querySelect, (OleDbConnection) connection);
				AddParameter (cmdSelect, "RoleId", roleId);
				using (OleDbDataReader reader = cmdSelect.ExecuteReader ()) {
					if (reader.Read ())
						// role is not empty
						return 3;
				}
			}

			string queryDelUsers = "DELETE FROM aspnet_UsersInRoles WHERE RoleId = ?";
			OleDbCommand cmdDelUsers = new OleDbCommand (queryDelUsers, (OleDbConnection) connection);
			AddParameter (cmdDelUsers, "RoleId", roleId);
			cmdDelUsers.ExecuteNonQuery ();

			string queryDelRole = "DELETE FROM aspnet_Roles WHERE ApplicationId = ? AND RoleId = ? ";
			OleDbCommand cmdDelRole = new OleDbCommand (queryDelRole, (OleDbConnection) connection);
			AddParameter (cmdDelRole, "ApplicationId", appId);
			AddParameter (cmdDelRole, "RoleId", roleId);
			cmdDelRole.ExecuteNonQuery ();

			return 0;
		}
开发者ID:runefs,项目名称:Marvin,代码行数:34,代码来源:DerbyRolesHelper.cs

示例14: InsertNewSummoner

        void InsertNewSummoner(Summoner summoner, DbConnection connection)
        {
            //We are dealing with a new summoner
            string query = string.Format("insert into summoner ({0}) values ({1})", GetGroupString(NewSummonerFields), GetPlaceholderString(NewSummonerFields));
            using (var newSummoner = Command(query, connection))
            {
                newSummoner.SetFieldNames(NewSummonerFields);

                newSummoner.Set(Profile.Identifier);

                newSummoner.Set(summoner.AccountId);
                newSummoner.Set(summoner.SummonerId);

                newSummoner.Set(summoner.SummonerName);
                newSummoner.Set(summoner.InternalName);

                newSummoner.Set(summoner.SummonerLevel);
                newSummoner.Set(summoner.ProfileIcon);

                newSummoner.Set(summoner.HasBeenUpdated);

                newSummoner.Set(summoner.UpdateAutomatically);

                long timestamp = Time.UnixTime();

                newSummoner.Set(timestamp);
                newSummoner.Set(timestamp);

                newSummoner.Execute();

                summoner.Id = GetInsertId(connection);
            }
        }
开发者ID:dimzy,项目名称:RiotControl,代码行数:33,代码来源:NewSummoner.cs

示例15: Insert

        public void Insert(DbConnection conn, string tableName, DataTable sourceData, Dictionary<string, string> columnMappings = null, DataRowState state = DataRowState.Added)
        {
            SqlConnection sqlConn = conn as SqlConnection;
            Check(conn);

            using (SqlBulkCopyWrapper sqlBC = new SqlBulkCopyWrapper(sqlConn))
            {
                sqlBC.BatchSize = 10000;
                sqlBC.BulkCopyTimeout = 600;
                sqlBC.DestinationTableName = tableName;
                if (columnMappings != null && columnMappings.Count > 0)
                {
                    foreach (var item in columnMappings)
                    {
                        sqlBC.ColumnMappings.Add(item.Value, item.Key);
                    }
                }
                else
                {
                    foreach (var item in sourceData.Columns.Cast<DataColumn>())
                    {
                        sqlBC.ColumnMappings.Add(item.ColumnName, item.ColumnName);
                    }

                }
                sqlBC.WriteToServer(sourceData, state);
            }
        }
开发者ID:piaolingzxh,项目名称:Justin,代码行数:28,代码来源:BulkCopySQL.cs


注:本文中的System.Data.Common.DbConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。