• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Common.DbConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: OnClosed

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


示例17: GetUnitOfWork

        public IUnitOfWork GetUnitOfWork()
        {
            if (_UnitOfWork != null)
                throw new Exception("A unit of work is already in use");
            else
            {
                if(! KeepConnectionAlive)
                {
                    _Context = new WADbContext(DatabaseName);

                    if(_FirstRequest)
                    {
                        _Context.Database.Initialize(force: false);
                        _FirstRequest = false;
                    }
                }
                else
                {
                    if(_DbConnection == null)
                    {
                        string connectionString = null;

                        if(DisableSqlCe)
                        {
                            _DbConnection = new SqlConnection();

                            connectionString = @" Server=.\SQLEXPRESS; Database=" +
                                DatabaseName +
                                "; Trusted_Connection=true";
                        }
                        else
                        {
                            // using SqlCe
                            _DbConnection = new SqlCeConnection();
                            connectionString = "Data Source=" + DatabaseName;
                        }

                        // create a context and initialize the db on startup
                        if(_FirstRequest)
                        {
                            using (var tempContext = new WADbContext(connectionString))
                            {
                                tempContext.Database.Initialize(force: false);
                            }

                            _FirstRequest = false;
                        }

                        _DbConnection.ConnectionString = connectionString;
                        _DbConnection.Open();
                    }

                    _Context = new WADbContext(_DbConnection, false);
                }

                _UnitOfWork = new UnitOfWork(_Context);

                return _UnitOfWork;
            }
        }
开发者ID:garygithub,项目名称:WADataAccessLayer,代码行数:60,代码来源:WADALFacade.cs


示例18: NuoDbCommand

 public NuoDbCommand(string query, DbConnection conn)
 {
     if (!(conn is NuoDbConnection))
         throw new ArgumentException("Connection is not a NuoDB connection", "conn");
     sqlText = query;
     connection = (NuoDbConnection)conn;
 }
开发者ID:helluvamatt,项目名称:nuodb-dotnet,代码行数:7,代码来源:NuoDbCommand.cs


示例19: Import

        static void Import(string simAreasPath, DbConnection connection)
        {
            var simarea = new SimAreasContext(connection, false, new DropCreateDatabaseAlways<SimAreasContext>());
            var engine = new FileHelperEngine(typeof(SimAreas));
            var entries = (SimAreas[])engine.ReadFile(simAreasPath);

            foreach (var entry in entries)
            {
                var area = (from s in simarea.SimAreas
                            where s.SimAreaName == entry.SimAreaName
                            select s).FirstOrDefault();
                if (area == null)
                {
                    area = new SimArea
                    {
                        SimAreaName = entry.SimAreaName,
                        Latitude = entry.Latitude,
                        Longitude = entry.Longitude,
                        Height = entry.Height,
                        GeoidSeparation = entry.GeoidSeparation,
                        OpsLimitFile = entry.OpsLimitFile,
                        SimLimitFile = entry.SimLimitFile,
                    };
                    simarea.SimAreas.Add(area);
                    simarea.SaveChanges();
                }

            }
        }
开发者ID:AuditoryBiophysicsLab,项目名称:ESME-Workbench,代码行数:29,代码来源:Program.cs


示例20: PrepareCommand

        private static void PrepareCommand(
            DbCommand command,
            DbConnection connection,
            DbTransaction transaction,
            CommandType commandType,
            string commandText,
            DbParameter[] commandParameters)
        {
            if (command == null) throw new ArgumentNullException("command");
            if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText");

            command.Connection = connection;
            command.CommandText = commandText;
            command.CommandType = commandType;

            if (transaction != null)
            {
                if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
                command.Transaction = transaction;
            }

            if (commandParameters != null)
            {
                AttachParameters(command, commandParameters);
            }
            return;
        }
开发者ID:freemsly,项目名称:cloudscribe,代码行数:27,代码来源:AdoHelper.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Common.DbConnectionOptions类代码示例发布时间:2022-05-26
下一篇:
C# Common.DbCommand类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap