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


C# IDbConnection.Open方法代码示例

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


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

示例1: AzureProcessor

 public AzureProcessor(IDbConnection connection, IMigrationGenerator generator, IAnnouncer announcer, IMigrationProcessorOptions options, IDbFactory factory)
     : base(generator, announcer, options)
 {
     this.factory = factory;
      Connection = connection;
      connection.Open();
 }
开发者ID:fire-eagle,项目名称:fluentmigrator,代码行数:7,代码来源:AzureProcessor.cs

示例2: 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

示例3: SetUp

        public void SetUp()
        {
            linkConnection = connectionFactory.Create(connectionString);
            linkConnection.Open();
            linkRepository = new SQLiteLinkRepository(logger, linkConnection);
            linkRepository.Initialize();

            tagConnection = connectionFactory.Create(connectionString);
            tagConnection.Open();
            tagRepository = new SQLiteTagRepository(logger, tagTypeFactory, tagConnection);
            tagRepository.Initialize();

            mediaConnection = connectionFactory.Create(connectionString);
            mediaConnection.Open();
            mediaRepository = new SQLiteMediaRepository(logger, mediaFactory, mediaConnection);
            mediaRepository.Initialize();

            itemConnection = connectionFactory.Create(connectionString);
            itemConnection.Open();
            mediaItemRepository = new SQLiteMetadataRepository(logger, securityContext, mediaFactory, itemConnection);
            mediaItemRepository.Initialize();

            audioStreamFactory = new AudioStreamFactory();

            spider = new CatalogSpider(logger, securityContext, mediaFactory, linkRepository, tagRepository, mediaRepository, mediaItemRepository, audioStreamFactory);
        }
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:26,代码来源:CatalogSpiderTests.cs

示例4: Initialize

	public void Initialize()
	{
		DBHandlerAI = new DBHandlerAI();
		DBHandlerDialogue = new DBHandlerDialogue();

		//open main db
		string conn = "URI=file:" + Application.dataPath + "/GameData/Database/Main.s3db"; //Path to database.
		Debug.Log("Main Database Path is : "+conn);
		_mainDBConn = (IDbConnection)new SqliteConnection(conn);
		_mainDBConn.Open(); //Open connection to the database.

		//open AI db
		conn = "URI=file:" + Application.dataPath + "/GameData/Database/AI.s3db";
		_aiDBConn = (IDbConnection)new SqliteConnection(conn);
		_aiDBConn.Open(); //Open connection to the database.

		/*
		while (reader.Read ()) 
		{
			int value = reader.GetInt32(0);
			Debug.Log("value= " + value);
		}
		*/

		//following is a test
		DBHandlerAI.GetCharacterActionSet(0);


		DBHandlerDialogue.LoadNPCDialogue(null);
	}
开发者ID:rotorist,项目名称:Warzone,代码行数:30,代码来源:DBManager.cs

示例5: DeleteTable

        /// <summary>
        /// 利用DataTable更新数据库里面的记录
        /// </summary>
        /// <param name="strTableName"></param>
        /// <param name="pRecordset"></param>
        /// <param name="pConnection"></param>
        public static bool DeleteTable(string strTableName, IDbConnection pConnection)
        {
            try
            {
                if (pConnection == null)
                {
                    return false;
                }

                if (pConnection.State == ConnectionState.Closed)
                {
                    pConnection.Open();
                }
                string str = string.Format("Drop table  {0}", strTableName);

                if (!ExecuteSql(pConnection, str))
                {
                    return false;
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return false;
            }
            return true;
        }
开发者ID:hy1314200,项目名称:HyDM,代码行数:34,代码来源:AdoDbHelper.cs

示例6: CreateDefaultHmacService

        private HmacHttpService CreateDefaultHmacService()
        {
            var settings = GetSetting();
            var connectionStringName = settings.ConnectionStringName;
            if (ConfigurationManager.ConnectionStrings[connectionStringName] == null)
            {
                throw new HmacInvalidConfigException(String.Format("Connection string named {0} is missing.", connectionStringName));
            }
            var connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
            var userTableName = settings.UsersTableName;
            var applicationTableName = settings.AppsTableName;
            var serviceId = settings.ServiceId;
            var signatureParameterKey = settings.SignatureParameterKey;
            var useHexEncoding = settings.UseHexEncoding;

            _connection = new SqlConnection(connectionString);
            _connection.Open();

            return new HmacHttpService(serviceId, settings.Paths, signatureParameterKey)
            {
                UserRepository = new DapperUserRepository(_connection, userTableName),
                AppRepository = new DapperAppRepository(_connection, applicationTableName),
                HmacService = new HmacSha256Service { SignatureParameterKey = signatureParameterKey, UseHexEncoding = useHexEncoding}
            };
        }
开发者ID:aduggleby,项目名称:dragon,代码行数:25,代码来源:HmacHttpModule.cs

示例7: 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

示例8: 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

示例9: 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

示例10: MyWorldDbAccess

 public MyWorldDbAccess()
 {
     var config = Store.config;
     /* Params: Host, port, database, user, password */
     conn = new MySqlConnection("Server=" + config.dbParams.Host + ";" + "Database=" + config.dbParams.DatabaseName + ";" + "User ID=" + config.dbParams.Username + ";" + "Password=" + config.dbParams.Password + ";" + "Pooling=false;");
     conn.Open();
 }
开发者ID:hdneo,项目名称:mxo-hd,代码行数:7,代码来源:MyWorldDbAccess.cs

示例11: 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

示例12: SetUpFixture

		public void SetUpFixture()
		{
			_connectionStringBuilder = new AseConnectionStringBuilder();
			_connectionStringBuilder.ConnectionString = "Data Source=testserver;Port=5000;User ID=sa;Password=Password1";
			_connection = new AseConnection(_connectionStringBuilder.ConnectionString);
			_connection.Open();
		}
开发者ID:gblence,项目名称:Insight.Database,代码行数:7,代码来源:SybaseAseTests.cs

示例13: Init

		public void Init (SessionStateModule module, HttpApplication context, SessionConfig config)
		{
			string connectionTypeName;
			string providerAssemblyName;
			string cncString;

			this.config = config;

			GetConnectionData (out providerAssemblyName, out connectionTypeName, out cncString);
			if (cncType == null) {
				Assembly dbAssembly = Assembly.Load (providerAssemblyName);
				cncType = dbAssembly.GetType (connectionTypeName, true);
				if (!typeof (IDbConnection).IsAssignableFrom (cncType))
					throw new ApplicationException ("The type '" + cncType +
							"' does not implement IDB Connection.\n" +
							"Check 'DbConnectionType' in server.exe.config.");
			}

			cnc = (IDbConnection) Activator.CreateInstance (cncType);
			cnc.ConnectionString = cncString;
			try {
				cnc.Open ();
			} catch (Exception exc) {
				cnc = null;
				throw exc;
			}
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:27,代码来源:SessionSQLServerHandler.cs

示例14: MainWindow

    public MainWindow()
        : base(Gtk.WindowType.Toplevel)
    {
        Build ();

        string connectionString = "Server=localhost;Database=dbprueba;User Id=javi;Password=sistemas";
        ApplicationContext.Instance.DbConnection = new NpgsqlConnection(connectionString);
        dbConnection = ApplicationContext.Instance.DbConnection;
        dbConnection.Open ();

        IDbCommand dbCommand = dbConnection.CreateCommand ();
        dbCommand.CommandText =
            "select a.id, a.nombre, a.precio, c.nombre as categoria " +
            "from articulo a left join categoria c " +
            "on a.categoria = c.id";

        IDataReader dataReader = dbCommand.ExecuteReader ();

        TreeViewExtensions.Fill (treeView, dataReader);
        dataReader.Close ();

        dataReader = dbCommand.ExecuteReader ();
        TreeViewExtensions.Fill (treeView, dataReader);
        dataReader.Close ();
    }
开发者ID:javisanchez,项目名称:ad,代码行数:25,代码来源:MainWindow.cs

示例15: SqlDBTransaction

 public SqlDBTransaction(SqlDB db)
     : base(db.ConnectionString, db.SqlAnalyzer, db.StrictTables)
 {
     _conn = db._getConnection();
     _conn.Open();
     _transaction = _conn.BeginTransaction();
 }
开发者ID:badjer,项目名称:Lasy,代码行数:7,代码来源:SqlDBTransaction.cs


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