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

C# DB2.DB2Connection类代码示例

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

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



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

示例1: ExecuteSqlTran

        /// <summary>
        /// 执行多条SQL语句,实现数据库事务。
        /// </summary>
        /// <param name="SQLStringList">ArrayList</param>
        public static void ExecuteSqlTran(ArrayList sqlList)
        {
            bool mustCloseConnection = false;
            string ConString = System.Configuration.ConfigurationSettings.AppSettings["conInsertDB2"].ToString();
            using (DB2Connection conn = new DB2Connection(ConString))
            {
                conn.Open();
                using (DB2Transaction trans = conn.BeginTransaction())
                {
                    DB2Command cmd = new DB2Command();
                    try
                    {
                        for (int i = 0; i < sqlList.Count; i++)
                        {
                            string cmdText = sqlList[i].ToString();
                            PrepareCommand(cmd, conn, trans, CommandType.Text, cmdText, null, out mustCloseConnection);
                            int val = cmd.ExecuteNonQuery();

                        }
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                    finally
                    {
                        conn.Close();
                        cmd.Dispose();
                    }
                }
            }
        }
开发者ID:eseawind,项目名称:YCJN,代码行数:38,代码来源:DBdb2.cs


示例2: GetBexisRights

 internal List<Right> GetBexisRights(string dataBase,  Dictionary<int, int> dataSetsMapping)
 {
     List<Right> bexisRights = new List<Right>();
     string datasetQuery = "";
     foreach (var dataSetMapping in dataSetsMapping)
     {
         datasetQuery += "DATASETID = "+ dataSetMapping.Key;
         if (dataSetsMapping.Last().Key != dataSetMapping.Key)
             datasetQuery += " or ";
     }
     if (dataSetsMapping.Any())
     {
         datasetQuery = "where " + datasetQuery + "";
     }
     // DB query
     string mySelectQuery = "SELECT ROLENAME, DATASETID, FOREDIT, APPLICATIONNAME FROM \"PROVIDER\".\"RIGHTS\"   "+ datasetQuery;
     DB2Connection connect = new DB2Connection(dataBase);
     DB2Command myCommand = new DB2Command(mySelectQuery, connect);
     connect.Open();
     DB2DataReader myReader = myCommand.ExecuteReader();
     while (myReader.Read())
     {
         bexisRights.Add(new Right()
         {
             RoleName = myReader.GetString(0),
             DataSetId = (int)(myReader.GetValue(1)),
             CanEdit = myReader.GetString(2)=="N"?false:true
         });
     }
     myReader.Close();
     connect.Close();
     return bexisRights;
 }
开发者ID:BEXIS2,项目名称:Core,代码行数:33,代码来源:SecurityMigration.cs


示例3: CreateCommand

        /// <summary>
        /// 创建DB2Command命令,指定数据库连接对象,存储过程名和参数.
        /// </summary>
        /// <remarks>
        /// 示例:  
        ///  DB2Command command = CreateCommand(conn, "AddCustomer", "CustomerID", "CustomerName");
        /// </remarks>
        /// <param name="connection">一个有效的数据库连接对象</param>
        /// <param name="spName">存储过程名称</param>
        /// <param name="sourceColumns">源表的列名称数组</param>
        /// <returns>返回DB2Command命令</returns>
        public static DB2Command CreateCommand(DB2Connection connection, string spName, params string[] sourceColumns)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName");

            // 创建命令
            DB2Command cmd = new DB2Command(spName, connection);
            cmd.CommandType = CommandType.StoredProcedure;

            // 如果有参数值
            if ((sourceColumns != null) && (sourceColumns.Length > 0))
            {
                // 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. ()
                DB2Parameter[] commandParameters = DB2HelperParameterCache.GetSpParameterSet(connection, spName);

                // 将源表的列到映射到DataSet命令中.
                for (int index = 0; index < sourceColumns.Length; index++)
                    commandParameters[index].SourceColumn = sourceColumns[index];

                // Attach the discovered parameters to the DB2Command object
                AttachParameters(cmd, commandParameters);
            }

            return cmd;
        }
开发者ID:eseawind,项目名称:sac-pt,代码行数:36,代码来源:DB2Helper.cs


示例4: GetDbConn

        public static IDbConnection GetDbConn(string dbname, MDataBaseType type)
        {
            IDbConnection conn = null;
            string connstr = GetBDConnString(dbname);
            switch (type)
            {
                case MDataBaseType.MYSQL:
                    conn = new MySqlConnection(connstr);
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }

                    break;
                case MDataBaseType.SQLSERVER:
                    conn = new SqlConnection(connstr);
                    break;
                case MDataBaseType.DB2:
                    conn = new DB2Connection(connstr);
                    break;
                case MDataBaseType.UNKNOW:
                    throw new Exception("未知数据库类型,创建数据库链接失败");
            }

            return conn;
        }
开发者ID:HelloAmy,项目名称:01component,代码行数:26,代码来源:ConnectionFactory.cs


示例5: CreateConnection

		protected override IDbConnection CreateConnection()
		{
			DB2Connection conn = new DB2Connection(ConnectionString);

			conn.Open();

			return conn;
		}
开发者ID:TheMouster,项目名称:coolstorage,代码行数:8,代码来源:CSDataProviderDB2.cs


示例6: DB2Command

		public DB2Command(string commandStr, DB2Connection con) : this()
		{
			db2Conn = con;
			commandText = commandStr;
			if(con != null)
			{
				con.AddCommand(this);
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:9,代码来源:DB2Command.cs


示例7: GetRealOpenConnection

		public DB2OpenConnection GetRealOpenConnection(DB2Connection connection)
		{
			if(pool != null)
			{
				return pool.GetOpenConnection(connection);
			}
			else
			{
				return new DB2OpenConnection(this, connection);
			}
		}
开发者ID:runefs,项目名称:Marvin,代码行数:11,代码来源:DB2ConnectionSettings.cs


示例8: GetOpenConnection

		public DB2OpenConnection GetOpenConnection(DB2Connection db2Conn)
		{
			DB2OpenConnection connection = null;
			lock(openFreeConnections.SyncRoot)
			{
				if((connectionSettings.ConnectionPoolSizeMax > 0) &&
					(connectionsOpen >= connectionSettings.ConnectionPoolSizeMax))
				{
					throw new ArgumentException("Maximum connections reached for connectionstring");
				}

				while(connectionsOpen > connectionsInUse)
				{
					connection = (DB2OpenConnection)openFreeConnections[openFreeConnections.Count - 1];
					openFreeConnections.RemoveAt(openFreeConnections.Count - 1);

					// check if connection is dead
					int isDead;
					short sqlRet = DB2CLIWrapper.SQLGetConnectAttr(connection.DBHandle, DB2Constants.SQL_ATTR_CONNECTION_DEAD, out isDead, 0, IntPtr.Zero);
					if(((sqlRet == DB2Constants.SQL_SUCCESS_WITH_INFO) || (sqlRet == DB2Constants.SQL_SUCCESS)) &&
						(isDead == DB2Constants.SQL_CD_FALSE))
					{
						connectionsInUse++;
						break;
					}
					else
					{
						connectionsOpen--;
						connection.Dispose();
						connection = null;
					}

				}
				if(connectionsOpen == connectionsInUse)
				{
					if(timer != null)
					{
						timer.Dispose();
						timer = null;
					}
				}
			}
			if(connection == null)
			{
				openFreeConnections.Clear();
				connectionsUsableOffset = 0;

				connection = new DB2OpenConnection(connectionSettings, db2Conn);
				connectionsOpen++;
				connectionsInUse++;
			}

			return connection;
		}
开发者ID:runefs,项目名称:Marvin,代码行数:54,代码来源:DB2ConnectionPool.cs


示例9: SitioCentral

        public SitioCentral(String id, String cc,List<SuperGridControl> sgc)
            : base(id, cc)
        {
            conexion = new DB2Connection(cadena_conexion);

            SPG = new SitioPG("CONTROL_INTERNO", dame_cc_de("CONTROL_INTERNO"));
            SO = new SitioOracle("FARMACIA", dame_cc_de("FARMACIA"));
            SM1 = new SitioMySQL("CONSULTORIO1", dame_cc_de("CONSULTORIO1"));
            SM2 = new SitioMySQL("CONSULTORIO2", dame_cc_de("CONSULTORIO2"));
            SM3 = new SitioMySQL("CONSULTORIO3", dame_cc_de("CONSULTORIO3"));
            grids = sgc;
        }
开发者ID:jluisacosta,项目名称:Clinic-Module,代码行数:12,代码来源:SitioCentral.cs


示例10: IBMBuldCopy

        public void IBMBuldCopy()
        {
            string sql_bruv_1 = "Server=10.24.1.202:446;Database=BRUVDB4V;UID=ATWO;PWD=24rete31;Max Pool Size=100;Min Pool Size=10;";
            string sql_frymek = "Server=10.27.5.197:50000;Database=BRUV;UID=db2admin;[email protected]#$;Max Pool Size=100;Min Pool Size=10;";

            try
            {
                using (DB2Connection myConn = new DB2Connection(sql_bruv_1))
                {
                    using (DB2Connection conn = new DB2Connection(sql_frymek))
                    {
                        myConn.Open();
                        conn.Open();

                        log.InfoFormat("{0}: Time elapsed: {1}", Table, DateTime.Now);
                        string myInsertQuery = String.Format("SELECT * FROM RREV.{0}", Table);

                        using (DB2Command myDB2Command = new DB2Command(myInsertQuery, myConn))
                        {
                            using (DB2DataReader reader = myDB2Command.ExecuteReader())
                            {
                                using (DB2BulkCopy salesCopy = new DB2BulkCopy(conn))
                                {
                                    salesCopy.DestinationTableName = String.Format("ATWO.{0}", Table);
                                    salesCopy.WriteToServer(reader);
                                    var errors = salesCopy.Errors;
                                    if (errors.Count > 0)
                                    {
                                        log.ErrorFormat("table:{0}, errors:{1}", Table, errors.Count);
                                        foreach (var er in errors)
                                        {
                                            log.ErrorFormat("table:{0}, msg:{1}", Table, er.ToString());
                                        }
                                    }
                                    salesCopy.Close();

                                    myConn.Close();
                                    conn.Close();
                                }
                            }
                        }
                    }
                }
                log.InfoFormat("{0}: Time elapsed: {1}", Table, DateTime.Now);
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
                Console.WriteLine(String.Format("error: {0} with exception: {1}", Table, ex.Message));
            }
        }
开发者ID:Zawulon,项目名称:ETL,代码行数:51,代码来源:IBMBulkCopy.cs


示例11: GetColumnList

        public List<MColumn> GetColumnList(string tableName)
        {
            string connstr = ConnectionFactory.TRSDbConnString;
            List<MColumn> ret = new List<MColumn>();
            using (DB2Connection conn = new DB2Connection(connstr))
            {
                conn.Open();
                var dao = DALFactory.GetSchemaDAO(MDataBaseType.DB2, MDBAccessType.WRITE);

                ret = dao.GetColumnList(conn, tableName);
            }

            return ret;
        }
开发者ID:HelloAmy,项目名称:01component,代码行数:14,代码来源:BGetSchema.cs


示例12: DB2DataReader

		/// <summary>
		/// 
		/// </summary>
		/// <param name="con"></Connection object to Db2>
		/// <param name="com"></Command object>
		internal DB2DataReader(DB2Connection con, DB2Command com, CommandBehavior behavior)
		{
			db2Conn = con;
			db2Comm = com;
			this.behavior = behavior;
			hwndStmt = com.statementHandle;    //We have access to the results through the statement handle
			
			_resultSet = null;
			
			GetFieldCountAndAffectedRows();
			internalBuffer = Marshal.AllocHGlobal(internalBufferSize);

			isClosed = false;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:19,代码来源:DB2DataReader.cs


示例13: ConnectDatabase

 //Boolean result = false;
 public Boolean ConnectDatabase()
 {
     try
     {
         //ConnPath = "";
         Conn = new DB2Connection("Server=localhost; UserID=db2admin; Password=admin...; Database=HRESS;");
         Conn.Open();
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
开发者ID:nanluckana,项目名称:HR-ESS,代码行数:15,代码来源:clsDatabase.cs


示例14: GetFromBExIS

        // query bexis1 user from provider.users and generate a random password
        public List<UserProperties> GetFromBExIS(string DataBase)
        {
            List<UserProperties> transferUsers = new List<UserProperties>();

            // DB query
            string mySelectQuery = "select username, email, firstname, lastname, " +
                                   "organization, projectname, projectleader, " +
                                   "url, phone, mobile, fax, original, street, zipcode, city";
            mySelectQuery += " from provider.users;";
            DB2Connection connect = new DB2Connection(DataBase);
            DB2Command myCommand = new DB2Command(mySelectQuery, connect);
            connect.Open();
            DB2DataReader myReader = myCommand.ExecuteReader();
            // random password
            Random gen = new Random();
            while (myReader.Read())
            {
                UserProperties transferUser = new UserProperties();

                // bexis1 DB user data
                transferUser.username = myReader.GetValue(0).ToString();
                transferUser.email = myReader.GetValue(1).ToString();
                transferUser.firstname = myReader.GetValue(2).ToString();
                transferUser.lastname = myReader.GetValue(3).ToString();
                transferUser.organization = myReader.GetValue(4).ToString();
                transferUser.projectname = myReader.GetValue(5).ToString();
                transferUser.projectleader = myReader.GetValue(6).ToString();
                transferUser.url = myReader.GetValue(7).ToString();
                transferUser.phone = myReader.GetValue(8).ToString();
                transferUser.mobile = myReader.GetValue(9).ToString();
                transferUser.fax = myReader.GetValue(10).ToString();
                transferUser.original = myReader.GetValue(11).ToString();
                transferUser.street = myReader.GetValue(12).ToString();
                transferUser.zipcode = myReader.GetValue(13).ToString();
                transferUser.city = myReader.GetValue(14).ToString();
                // bexis2 required security data
                transferUser.password = randomPassword(ref gen); // random password
                transferUser.securityQuestionId = 1;
                transferUser.securityAnswer = "1";
                transferUser.authenticatorId = 1;

                // add to list; username required
                if (transferUser.username != "")
                    transferUsers.Add(transferUser);
            }
            myReader.Close();
            connect.Close();

            return transferUsers;
        }
开发者ID:BEXIS2,项目名称:Core,代码行数:51,代码来源:UserMigration.cs


示例15: GetTableList

        public List<MTableDesc> GetTableList(string creator)
        {
            string connstr = ConnectionFactory.TRSDbConnString;

            List<MTableDesc> ret = null;

            using (DB2Connection conn = new DB2Connection(connstr))
            {
                conn.Open();
                var dao = DALFactory.GetSchemaDAO(MDataBaseType.DB2, MDBAccessType.WRITE);

                ret = dao.GetTableList(conn, creator);
            }

            return ret;
        }
开发者ID:HelloAmy,项目名称:01component,代码行数:16,代码来源:BGetSchema.cs


示例16: GetBexisRoles

 internal List<string> GetBexisRoles(string DataBase)
 {
     List<string> bexisRoles = new List<string>();
     // DB query
     string mySelectQuery = "SELECT ROLENAME, APPLICATIONNAME FROM \"PROVIDER\".\"ROLES\"";
     DB2Connection connect = new DB2Connection(DataBase);
     DB2Command myCommand = new DB2Command(mySelectQuery, connect);
     connect.Open();
     DB2DataReader myReader = myCommand.ExecuteReader();
     while (myReader.Read())
     {
         bexisRoles.Add(myReader.GetValue(0).ToString());
     }
     myReader.Close();
     connect.Close();
     return bexisRoles;
 }
开发者ID:BEXIS2,项目名称:Core,代码行数:17,代码来源:SecurityMigration.cs


示例17: GetBexisUsersInRole

 internal List<string> GetBexisUsersInRole(string dataBase, string roleName)
 {
     List<string> bexisUsersInRole = new List<string>();
     // DB query
     string mySelectQuery = "SELECT USERNAME FROM \"PROVIDER\".\"USERSINROLES\" where ROLENAME='" + roleName + "'";
     DB2Connection connect = new DB2Connection(dataBase);
     DB2Command myCommand = new DB2Command(mySelectQuery, connect);
     connect.Open();
     DB2DataReader myReader = myCommand.ExecuteReader();
     while (myReader.Read())
     {
         bexisUsersInRole.Add(myReader.GetValue(0).ToString());
     }
     myReader.Close();
     connect.Close();
     return bexisUsersInRole;
 }
开发者ID:BEXIS2,项目名称:Core,代码行数:17,代码来源:SecurityMigration.cs


示例18: getMetadataXml

        public XmlDocument getMetadataXml(string dataSetID, string DataBase)
        {
            XmlDocument doc = new XmlDocument();

            string mySelectQuery = "select datasetid, metadata";
            mySelectQuery += " from explorer.datasets where datasetid = " + dataSetID + ";";
            DB2Connection connect = new DB2Connection(DataBase);
            DB2Command myCommand = new DB2Command(mySelectQuery, connect);
            connect.Open();
            DB2DataReader myReader = myCommand.ExecuteReader();
            while (myReader.Read())
            {
                doc.LoadXml(myReader.GetString(1));
            }
            myReader.Close();
            connect.Close();

            return doc;
        }
开发者ID:BEXIS2,项目名称:Core,代码行数:19,代码来源:MetadataCreator.cs


示例19: GetConnection

		/// <summary>
		/// Please refer to the documentation of <see cref="GentleProvider"/> and the
		/// <see cref="IGentleProvider"/> interface it implements for details. 
		/// </summary>
		public override IDbConnection GetConnection()
		{
			try
			{
				IDbConnection dbc = new DB2Connection( ConnectionString );
				dbc.Open();
				Check.VerifyEquals( dbc.State, ConnectionState.Open, Error.NoNewConnection );
				return dbc;
			}
			catch( GentleException )
			{
				throw; // expose the errors raised by ourselves (i.e. the data framework) in the try block
			}
			catch( Exception e )
			{
				Check.Fail( e, Error.DatabaseUnavailable, Name, ConnectionString );
				throw new GentleException( Error.Unspecified, "Unreachable code!" );
			}
		}
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:23,代码来源:DB2Provider.cs


示例20: DB2CheckReturn

		public static void DB2CheckReturn(short sqlRet, short handleType, IntPtr handle, string message, DB2Connection connection)
		{
			switch (sqlRet) 
			{
				case DB2Constants.SQL_SUCCESS_WITH_INFO:
					if(connection != null)
					{
						connection.OnInfoMessage(handleType, handle);
					}
					goto case DB2Constants.SQL_SUCCESS;
				case DB2Constants.SQL_SUCCESS:
				case DB2Constants.SQL_NO_DATA:
					return;

				case DB2Constants.SQL_INVALID_HANDLE:
					throw new ArgumentException("Invalid handle");

				default:
				case DB2Constants.SQL_ERROR:
					throw new DB2Exception(handleType, handle, message);
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:22,代码来源:DB2ClientUtils.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# ResultMapping.ResultProperty类代码示例发布时间:2022-05-26
下一篇:
C# HypervResource.WmiException类代码示例发布时间: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