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


C# IDbConnection.Close方法代码示例

本文整理汇总了C#中IDbConnection.Close方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.Close方法的具体用法?C# IDbConnection.Close怎么用?C# IDbConnection.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDbConnection的用法示例。


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

示例1: OracleBlobOutputStream

		/// <summary>
		/// Creates a new instance of the <see cref="SqlClientInputStream" /> class for the specified connection string, table
		/// data field, and where criteria.
		/// </summary>
		/// <param name="connectionString">The connection string of the database to use.</param>
		/// <param name="table">The table in which the data is stored.</param>
		/// <param name="dataField">The field in which the data is stored</param>
		/// <param name="whereCriteria">The where criteria that identifies the record.</param>
		public OracleBlobOutputStream(string connectionString, string table, string dataField, string whereCriteria)
		{
			// TODO: add buffering
			_cn = OracleBlobUploadStreamProvider.CreateConnection(connectionString);
			_cmd = _cn.CreateCommand();

            _cmd.CommandText = "SELECT " + dataField + " FROM " + table + " WHERE " + whereCriteria;

            try
            {
                _cn.Open();

                IDataReader rd = _cmd.ExecuteReader(CommandBehavior.SingleRow);

                rd.Read();

                object blob = rd.GetType().InvokeMember("GetOracleBlob", BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, rd, new object[] {0});

                _blob = new ReflectWrapper(blob);
            }
            catch
            {
				_cn.Close();
			}
		}
开发者ID:codingbat,项目名称:BandCamp,代码行数:33,代码来源:OracleBlobOutputStream.cs

示例2: RunStoredProcedure

        /// Runs a stored procedure
        /// </summary>
        /// <param name="procedureName"></param>
        /// <param name="QueryParameters"></param>
        /// <param name="OutputParameters"></param>
        /// <param name="DB"></param>
        public virtual void RunStoredProcedure(IDbConnection connection, string procedureName,
            IEnumerable<IDataParameter> inputParameters,
            IEnumerable<IDataParameter> outputParameters,
            IDbTransaction transaction,
            CommandBehavior commandBehavior)
        {
            SqlCommand cmd = new SqlCommand(procedureName, (SqlConnection)connection);
            cmd.CommandType = CommandType.StoredProcedure;

            ProcessSql(procedureName, inputParameters);

            foreach (var parm in inputParameters)
            {
                cmd.Parameters.Add(parm);
            }
            if (outputParameters != null)
            {
                foreach (SqlParameter parm in outputParameters)
                {
                    parm.Direction = ParameterDirection.Output;
                    //OutputParameters[i].Value = -1;
                    cmd.Parameters.Add(parm);
                }
            }

            ExecuteSqlFinal(new Action(() =>
            {
                cmd.ExecuteScalar();
            }));
            if (commandBehavior == CommandBehavior.CloseConnection)
            {
                connection.Close();
            }
            OnQueryComplete();
        }
开发者ID:jamietre,项目名称:IQMap,代码行数:41,代码来源:MSSQLDataStorageController.cs

示例3: AffectData

        public static int AffectData(string TSQL, IDbConnection myConn, IDbTransaction myTrans, List<IDbDataParameter> myParams)
        {
            bool mustClose = false;
            if (myConn == null)
            {
                mustClose = true;
                myConn = clsConn.getConnOLE();
            }
            if (myConn.State != ConnectionState.Open)
                myConn.Open();
            OleDbCommand myCMD = new OleDbCommand();
            //
            myCMD.Connection = myConn as OleDbConnection;
            if (myTrans != null)
                myCMD.Transaction = myTrans as OleDbTransaction;
            //
            myCMD.CommandType = CommandType.Text;
            myCMD.CommandText = TSQL;
            myCMD.CommandTimeout = 180000;//3 phut
            //
            if (myParams != null)
                AttachParameters(myCMD, myParams);

            int CMDResult = myCMD.ExecuteNonQuery();
            //
            if (mustClose) myConn.Close();
            return CMDResult;
        }
开发者ID:huamanhtuyen,项目名称:TagLo1,代码行数:28,代码来源:clsDalOLE.cs

示例4: Execute

        public bool Execute(string qry)
        {
            cn = new OleDbConnection(cnString.GetConnString());
            cmd = new OleDbCommand(qry, (OleDbConnection)cn);
            try
            {
                cn.Open();
                IDbTransaction tran = cn.BeginTransaction();
                cmd.Transaction = tran;

                int affectedRows = cmd.ExecuteNonQuery();
                Console.WriteLine(affectedRows);
                if (affectedRows > 0)
                {
                    tran.Commit();
                    return true;
                }
                else
                {
                    tran.Rollback();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                cn.Close();
            }
            return false;
        }
开发者ID:hksarwar,项目名称:JobSystem,代码行数:32,代码来源:WriteCommand.cs

示例5: checkName

        public bool checkName(string playername)
        {
            bool isinLog = false;
            playername = playername.Replace ("'", @"\'");
            IDbConnection dbcon;
            dbcon = new MySqlConnection (connectionString);
            dbcon.Open();
            IDbCommand dbcmd = dbcon.CreateCommand ();
            string sql =
             	  		    " SELECT * FROM terraria_tiles WHERE player = '" + playername + "' LIMIT 0, 1";
            dbcmd.CommandText = sql;
            IDataReader reader = dbcmd.ExecuteReader ();
            while (reader.Read()) {
                isinLog = true;
            }

            // clean up
            reader.Close ();
            reader = null;
            dbcmd.Dispose ();
            dbcmd = null;
            dbcon.Close();
            dbcon = null;
            //end check

            return isinLog;
        }
开发者ID:elevatorguy,项目名称:TDSM_mysql,代码行数:27,代码来源:MysqlPlugin_Mysql.cs

示例6: DiscoverSpParameterSet

        /// <summary>
        /// 探索运行时的存储过程,返回IDbDataParameter参数数组.
        /// 初始化参数值为 DBNull.Value.
        /// </summary>
        /// <param>一个有效的数据库连接</param>
        /// <param>存储过程名称</param>
        /// <param>是否包含返回值参数</param>
        /// <returns>返回IDbDataParameter参数数组</returns>
        private static IDbDataParameter[] DiscoverSpParameterSet(IDbConnection connection, string spName, bool includeReturnValueParameter)
        {
            if (connection == null) throw new ArgumentNullException("IDbConnection 连接对象为NULL");
            if (spName == null || spName.Length == 0) throw new ArgumentNullException("存储过程名称为null");
            IDbCommand cmd = DataBaseFactory.GetIDbCommand();//. new IDbCommand(spName, connection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = spName;
            connection.Open();
            // 检索cmd指定的存储过程的参数信息,并填充到cmd的Parameters参数集中.
           // SqlCommandBuilder.DeriveParameters(cmd); //这里考虑一下如何是区分不同数据库的填充
           
            connection.Close();
            // 如果不包含返回值参数,将参数集中的每一个参数删除.

            if (!includeReturnValueParameter)
            {
                cmd.Parameters.RemoveAt(0);
            }
            // 创建参数数组
            IDbDataParameter[] discoveredParameters = new IDbDataParameter[cmd.Parameters.Count];
            // 将cmd的Parameters参数集复制到discoveredParameters数组.
            cmd.Parameters.CopyTo(discoveredParameters, 0);
            // 初始化参数值为 DBNull.Value.
            foreach (IDbDataParameter discoveredParameter in discoveredParameters)
            {
                discoveredParameter.Value = DBNull.Value;
            }
            return discoveredParameters;
        }
开发者ID:JuRogn,项目名称:OA,代码行数:37,代码来源:IDbParameterCache.cs

示例7: ReleaseClientConnection

        public virtual void ReleaseClientConnection(IDbConnection dbConnection)
        {
            if (dbConnection == null)
                return;

            dbConnection.Close();
            dbConnection.Dispose();
        }
开发者ID:ovuncgursoy,项目名称:SisoDb-Provider,代码行数:8,代码来源:SqlServerConnectionManager.cs

示例8: FillPrimaryKeysBySchema

        public static void FillPrimaryKeysBySchema(this SchemaDataSet.SchemaPrimaryKeysDataTable primaryKeysDataTable, string schema, IDbConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            const string SELECT_PRIMARY_KEYS = @"
SELECT        cons.TABLE_SCHEMA
            , cons.TABLE_NAME
            , cols.COLUMN_NAME
            , 0 AS IsMatch
    FROM            INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS cons 
    LEFT OUTER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS cols 
                ON  cons.CONSTRAINT_NAME = cols.CONSTRAINT_NAME
    WHERE   (cons.CONSTRAINT_TYPE = 'PRIMARY KEY') 
        AND (cons.TABLE_SCHEMA = @tableSchema)
    ORDER BY  cons.TABLE_SCHEMA
            , cons.TABLE_NAME
            , cols.COLUMN_NAME";

            primaryKeysDataTable.Clear();
            using (IDbCommand command = connection.CreateCommand())
            {
                command.CommandText = SELECT_PRIMARY_KEYS;

                IDbDataParameter parameter = command.CreateParameter();
                command.Parameters.Add(parameter);

                parameter.DbType = DbType.String;
                parameter.Direction = ParameterDirection.Input;
                parameter.ParameterName = "@tableSchema";
                parameter.Value = schema;

                ConnectionState state = connection.State;
                bool startedClosed = state == ConnectionState.Closed;
                try
                {
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        primaryKeysDataTable.BeginLoadData();
                        primaryKeysDataTable.Load(reader);
                        primaryKeysDataTable.EndLoadData();
                    }
                }
                finally
                {
                    if (startedClosed)
                    {
                        if (connection.State
                            != ConnectionState.Closed)
                        {
                            connection.Close();
                        }
                    }
                }
            }
        }
开发者ID:CodeCharm,项目名称:AuditFramework,代码行数:58,代码来源:SchemaDataSetExtensions.cs

示例9: CleanUp

	public static void CleanUp(IDataReader pmReader, IDbCommand pmCommand, IDbConnection pmConnection)
	{
		if (pmReader != null)
			pmReader.Close ();
		if (pmCommand != null)
			pmCommand.Dispose ();
		if (pmConnection != null)
			pmConnection.Close ();
	}
开发者ID:sakurazuka90,项目名称:DnD5BattleEngine,代码行数:9,代码来源:DatabaseController.cs

示例10: CreateFutureStackDb

        private static void CreateFutureStackDb(IDbConnection dbConnection)
        {
            if (dbConnection.State != ConnectionState.Open) dbConnection.Open();

            dbConnection.DropAndCreateTable<Customer>();
            dbConnection.DropAndCreateTable<Address>();

            dbConnection.Close();
        }
开发者ID:CharlesSelvaraj,项目名称:FutureStack,代码行数:9,代码来源:Program.cs

示例11: GetDatabaseNames

        /// <summary>
        /// Returns a list of database names.
        /// </summary>
        /// <param name="connection">A database connection to a server containing geodatabases.</param>
        /// <returns></returns>
        public static List<string> GetDatabaseNames(IDbConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            // Store the initial connection state.  If the connection is already open we will leave it open instead of closing it.
            var initConnectionState = connection.State;
            // Store the initial database in case we need to change it.
            string originalDatabase = connection.Database;

            List<string> output = null;

            try
            {
                // Open the connection if it is not already open.
                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                }

                // We need to use the "master" database.
                if (string.Compare(connection.Database, "master", true) != 0)
                {
                    Trace.WriteLine(string.Format("Changing database from {0} to master...", connection.Database));
                    connection.ChangeDatabase("master");
                }

                // Create the command to select the list of databases.
                var cmd = connection.CreateCommand();
                cmd.CommandText = Resources.ListDatabases;

                // Initialize the list of database names.
                output = new List<string>();

                // Execute the command and store the database names that are returned.
                using (var reader = cmd.ExecuteReader(CommandBehavior.Default))
                {
                    while (reader.Read())
                    {
                        string s = reader.GetString(0);
                        output.Add(s);
                    }
                }

            }
            finally
            {
                // Close the connection ONLY if it was not already opened when we started.
                if (connection != null && initConnectionState != ConnectionState.Open)
                {
                    connection.Close();
                }
            }

            return output;
        }
开发者ID:WSDOT-GIS,项目名称:ArcSDE-GDB-Info,代码行数:62,代码来源:DataAccess.cs

示例12: DisconnectionScope

        public DisconnectionScope(IDbConnection connection)
        {
            if (connection == null) throw new ArgumentNullException(nameof(connection));

            _connection = connection;
            _initState = connection.State;

            if (connection.State != ConnectionState.Closed)
                connection.Close();
        }
开发者ID:Core-Techs,项目名称:Common,代码行数:10,代码来源:DisconnectionScope.cs

示例13: ReleaseServerConnection

		public void ReleaseServerConnection(IDbConnection dbConnection)
		{
			if (dbConnection == null)
				return;

			if (dbConnection.State != ConnectionState.Closed)
				dbConnection.Close();

			dbConnection.Dispose();
		}
开发者ID:BlackMael,项目名称:SisoDb-Provider,代码行数:10,代码来源:SqlCe4ConnectionManager.cs

示例14: InitializeSchema

 public static void InitializeSchema(IDbConnection connection)
 {
     var assembly = Assembly.GetExecutingAssembly();
     var cmd = connection.CreateCommand();
     var stream = assembly.GetManifestResourceStream("Movies.Database.Schema.sql");
     var reader = new StreamReader(stream);
     var sql = reader.ReadToEnd();
     cmd.CommandText = sql;
     cmd.ExecuteNonQuery();
     connection.Close();
 }
开发者ID:jacobsimeon,项目名称:Movies,代码行数:11,代码来源:SessionFactoryInitializer.cs

示例15: CloseConnection

 public virtual void CloseConnection(IDbConnection conn)
 {
     try
     {
         conn.Close();
     }
     catch
     {
         throw new Exception("Could not close " + conn.GetType() + " connection");
     }
 }
开发者ID:eicrosoft,项目名称:VipSoft,代码行数:11,代码来源:ConnectionProvider.cs


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