Пример #1
0
		public void SetUpFixture()
		{
			DB2ConnectionStringBuilder connectionStringBuilder = new DB2ConnectionStringBuilder();
			connectionStringBuilder.ConnectionString = "Server=testserver:50000;Database=SAMPLE";
			connectionStringBuilder.UserID = "db2admin";
			connectionStringBuilder.Password = "******";

			_connectionStringBuilder = connectionStringBuilder;
			_connection = _connectionStringBuilder.Open();
		}
Пример #2
0
		public void SetUpFixture()
		{
			DB2ConnectionStringBuilder connectionStringBuilder = new DB2ConnectionStringBuilder();
            connectionStringBuilder.ConnectionString = "Server=localhost:50000;Database=sample";
			connectionStringBuilder.UserID = "db2inst1";
			connectionStringBuilder.Password = "******";

			_connectionStringBuilder = connectionStringBuilder;
			_connection = _connectionStringBuilder.Open();
		}
Пример #3
0
        private bool disposed = false; //used for the Dispose method

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Main constructor
        /// </summary>
        /// <param name="dataSource">Server name</param>
        /// <param name="initialCatalog">Data base name</param>
        /// <param name="userId">User Id</param>
        /// <param name="passWord">Password</param>
        /// <param name="persistSecurityInfo">Whether to keep password in memory or not</param>
        /// <param name="queryTimeout">Time in seconds for query execution time before a timeout exception</param>
        /// <param name="connectionTimeOut">Time in seconds for connection time before a timeout exception</param>
        public DBConnectorDB2(string dataSource, string initialCatalog, string userId, string passWord, 
                                bool persistSecurityInfo, int queryTimeout, int connectionTimeOut)
        {
            connectionString = new DB2ConnectionStringBuilder();
            connectionString.Database = initialCatalog;
            connectionString.allowDynamicSQL = true;
            connectionString.QueryTimeout = queryTimeout;
            connectionString.Server = dataSource;
            connectionString.UserID = userId;
            connectionString.Password = passWord;
            connectionString.PersistSecurityInfo = persistSecurityInfo;
            connectionString.Connect_Timeout = connectionTimeOut;
            Parameters = new List<DB2Parameter>();
            ErrorList = new List<Error>();
        }
Пример #4
0
        /// <summary>Damの選択</summary>
        private void cmbDataProvider_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                // 初期は、無効にして、ODP.NET、HiRDB選択時のみ有効にする。
                this.nudNumOfBind.Enabled = false;

                if (this.cmbDataProvider.SelectedItem.ToString() == Literal.DAP_SQL)
                {
                    //sqlClient
                    this._dam = new DamSqlSvr();

                    //接続文字列のサンプルを設定する(空の場合)。
                    SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();

                    csb.DataSource = this._ip;
                    csb.InitialCatalog = "Northwind";
                    csb.UserID = this._uid;
                    csb.Password = this._pwd;

                    this.txtCnnStr.Text = csb.ConnectionString;

                    // 状態
                    ((ToolStripStatusLabel)this.statBar.Items[0]).Text = this.RM_GetString("STATUS_SQL_CREATED");

                }
                else if (this.cmbDataProvider.SelectedItem.ToString() == Literal.DAP_OLE)
                {
                    //OLEDB.NET
                    this._dam = new DamOLEDB();

                    //接続文字列のサンプルを設定する(空の場合)。
                    OleDbConnectionStringBuilder csb = new OleDbConnectionStringBuilder();

                    csb.Provider = "Provider";
                    csb.DataSource = "DataSourceName";
                    csb.FileName = "FileName";

                    this.txtCnnStr.Text = csb.ConnectionString;

                    // 活性
                    this.nudNumOfBind.Enabled = true;

                    // 状態
                    ((ToolStripStatusLabel)this.statBar.Items[0]).Text = this.RM_GetString("STATUS_OLE_CREATED");

                }
                if (this.cmbDataProvider.SelectedItem.ToString() == Literal.DAP_ODB)
                {
                    //ODBC.NET
                    this._dam = new DamODBC();

                    //接続文字列のサンプルを設定する(空の場合)。
                    OdbcConnectionStringBuilder csb = new OdbcConnectionStringBuilder();

                    csb.Driver = "DriverName";
                    csb.Dsn = "DataSourceName";

                    this.txtCnnStr.Text = csb.ConnectionString;

                    // 活性
                    this.nudNumOfBind.Enabled = true;

                    // 状態
                    ((ToolStripStatusLabel)this.statBar.Items[0]).Text = this.RM_GetString("STATUS_ODB_CREATED");

                }
                if (this.cmbDataProvider.SelectedItem.ToString() == Literal.DAP_ORA)
                {
                    //Oracle Client
                    this._dam = new DamOraClient();

                    //接続文字列のサンプルを設定する(空の場合)。
                    System.Data.OracleClient.OracleConnectionStringBuilder csb = new System.Data.OracleClient.OracleConnectionStringBuilder();

                    csb.DataSource = this._ip + "/orcl";
                    csb.UserID = this._uid;
                    csb.Password = this._pwd;

                    this.txtCnnStr.Text = csb.ConnectionString;

                    // 活性
                    this.nudNumOfBind.Enabled = true;

                    // 状態
                    ((ToolStripStatusLabel)this.statBar.Items[0]).Text = this.RM_GetString("STATUS_ODP_CREATED");

                } 
                if (this.cmbDataProvider.SelectedItem.ToString() == Literal.DAP_ODP)
                {
                    //ODP.NET
                    this._dam = new DamOraOdp();

                    //接続文字列のサンプルを設定する(空の場合)。
                    Oracle.DataAccess.Client.OracleConnectionStringBuilder csb = new Oracle.DataAccess.Client.OracleConnectionStringBuilder();

                    csb.DataSource = this._ip + "/orcl";
                    csb.UserID = this._uid;
                    csb.Password = this._pwd;

                    this.txtCnnStr.Text = csb.ConnectionString;

                    // 活性
                    this.nudNumOfBind.Enabled = true;

                    // 状態
                    ((ToolStripStatusLabel)this.statBar.Items[0]).Text = this.RM_GetString("STATUS_ODP_CREATED");

                }
                else if (this.cmbDataProvider.SelectedItem.ToString() == Literal.DAP_DB2)
                {
                    //DB2.NET
                    this._dam = new DamDB2();

                    //接続文字列のサンプルを設定する(空の場合)。
                    DB2ConnectionStringBuilder csb = new DB2ConnectionStringBuilder();

                    //csb.Server = this._ip + ":50000";
                    csb.Database = "SAMPLE";
                    csb.UserID = this._uid;
                    csb.Password = this._pwd;

                    this.txtCnnStr.Text = csb.ConnectionString;

                    // 状態
                    ((ToolStripStatusLabel)this.statBar.Items[0]).Text = this.RM_GetString("STATUS_DB2_CREATED");

                }
                //else if (this.cmbDataProvider.SelectedItem.ToString() == Literal.DAP_HiRDB)
                //{
                //    //HiRDBデータ プロバイダ
                //    this._dam = new DamHiRDB();

                //    //接続文字列のサンプルを設定する(空の場合)。
                //    //HiRDBデータ プロバイダは、ConnectionStringBuilderがない。
                //    string csb = "";
                //    csb += "DataSource=C:\\Windows\\HiRDB.ini;";
                //    csb += "UID=" + this._uid + ";";
                //    csb += "PWD=" + this._pwd + ";";

                //    this.txtCnnStr.Text = csb;

                //    // 活性
                //    this.nudNumOfBind.Enabled = true;

                //    // 状態
                //    ((ToolStripStatusLabel)this.statBar.Items[0]).Text = Literal.STATUS_HRD_CREATED;
                //}
                else if (this.cmbDataProvider.SelectedItem.ToString() == Literal.DAP_MySQL)
                {
                    //MySQL Connector/NET
                    this._dam = new DamMySQL();

                    //接続文字列のサンプルを設定する(空の場合)。
                    MySqlConnectionStringBuilder csb = new MySqlConnectionStringBuilder();

                    csb.Server = this._ip;
                    csb.Database = "test";
                    csb.UserID = this._uid;
                    csb.Password = this._pwd;

                    this.txtCnnStr.Text = csb.ConnectionString;

                    // 状態
                    ((ToolStripStatusLabel)this.statBar.Items[0]).Text = this.RM_GetString("STATUS_MSL_CREATED");

                }
                else if (this.cmbDataProvider.SelectedItem.ToString() == Literal.DAP_PstgrS)
                {
                    //Npgsql
                    this._dam = new DamPstGrS();

                    //接続文字列のサンプルを設定する(空の場合)。
                    //NpgsqlConnectionStringBuilderは、冗長な接続文字列を返すので使わない。

                    //NpgsqlConnectionStringBuilder csb = new NpgsqlConnectionStringBuilder();
                    string csb = "";

                    //csb.Host = this._ip;
                    //csb.Database = "postgres";
                    //csb.UserName = this._uid;
                    //csb.Password = this._pwd;
                    csb += "HOST=" + this._ip + ";";
                    csb += "DATABASE=postgres;";
                    csb += "UID=" + this._uid + ";";
                    csb += "PWD=" + this._pwd + ";";

                    this.txtCnnStr.Text = csb;

                    // 状態
                    ((ToolStripStatusLabel)this.statBar.Items[0]).Text = this.RM_GetString("STATUS_PGS_CREATED");
                }
                else
                {
                    //ありえない
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #5
0
 /// <summary>
 /// Main constructor
 /// </summary>
 /// <param name="connString">A connection string to the database</param>
 public DBConnectorDB2(string connString)
 {
     connectionString = new DB2ConnectionStringBuilder(connString);
     Parameters = new List<DB2Parameter>();
     ErrorList = new List<Error>();
 }
Пример #6
0
		public void TestReliableConnection()
		{
			int retries = 0;
			var retryStrategy = new RetryStrategy();
			retryStrategy.MaxRetryCount = 1;
			retryStrategy.Retrying += (sender, re) => { Console.WriteLine("Retrying. Attempt {0}", re.Attempt); retries++; };

			try
			{
				DB2ConnectionStringBuilder connectionStringBuilder = new DB2ConnectionStringBuilder();
				connectionStringBuilder.ConnectionString = "Server=testserver:9999;Database=SAMPLE";
				connectionStringBuilder.UserID = "db2admin";
				connectionStringBuilder.Password = "******";
				using (var reliable = new ReliableConnection<DB2Connection>(connectionStringBuilder.ConnectionString, retryStrategy))
				{
					reliable.Open();
				}
			}
			catch
			{
			}

			Assert.AreEqual(1, retries);
		}
Пример #7
-1
        /// <summary>
        /// Overrides the native Didspose method
        /// </summary>
        /// <param name="disposing">True or False</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // Clear all property values that maybe have been set
                    // when the class was instantiated
                    Clear();
                    connectionString.Clear();
                    connectionString = null;
                }

                // Indicate that the instance has been disposed.
                disposed = true;
            }
        }