private void CreateConnectionFromParameters() { DbConnectionStringBuilder builder = _factory.CreateConnectionStringBuilder(); try { // most builders should translate these generic keywords // to provider-specific native keywords. if (!String.IsNullOrEmpty(this.UserName)) { builder.Add("User", this.UserName); } if (!String.IsNullOrEmpty(this.Password)) { builder.Add("Password", this.Password); } if (!String.IsNullOrEmpty(this.Server)) { builder.Add("Server", this.Server); } if (!String.IsNullOrEmpty(this.Database)) { builder.Add("Database", this.Database); } } catch (ArgumentException ex) { // invalid keyword(s) throw new ArgumentException(GetValidKeywords(builder), ex); } _connection = _factory.CreateConnection(); _connection.ConnectionString = builder.ConnectionString; }
/// <summary> /// 判断数据库连接 是否一致 /// </summary> /// <param name="conn"></param> /// <param name="connectionString"></param> /// <returns>true:一致</returns> private bool ConnectionStringCompare(DbConnection conn, string connectionString) { DbProviderFactory factory = DbProviderFactories.GetFactory(conn); DbConnectionStringBuilder a = factory.CreateConnectionStringBuilder(); a.ConnectionString = conn.ConnectionString; DbConnectionStringBuilder b = factory.CreateConnectionStringBuilder(); b.ConnectionString = connectionString; return(a.EquivalentTo(b)); }
public override DbConnectionStringBuilder CreateConnectionStringBuilder(string connectionString) { var builder = dbFactory.CreateConnectionStringBuilder(); builder.ConnectionString = connectionString; return(builder); }
public static DbConnectionStringBuilder CreateConnectionStringBuilder(this DbProviderFactory @this, string connectionString) { var dbConnectionStringBuilder = @this.CreateConnectionStringBuilder() !; dbConnectionStringBuilder.ConnectionString = connectionString; return(dbConnectionStringBuilder); }
/// <summary> /// 获取一个DbContext对象 /// </summary> /// <param name="name">连接名称</param> /// <param name="autoClose">是否自动关闭</param> /// <returns>DbContext对象</returns> public static DbContext GetContext(string name, bool autoClose) { //得到映射后连接名称 name = DbConnectionMappingContext.GetMappedConnectionName(name); DbProviderFactory factory = DbConnectionManager.GetDbProviderFactory(name); DbConnectionStringBuilder csb = factory.CreateConnectionStringBuilder(); csb.ConnectionString = DbConnectionManager.GetConnectionString(name); bool enlist = true; if (csb.ContainsKey("enlist")) { enlist = (bool)csb["enlist"]; } DbContext result = null; if (enlist) { result = new AutoEnlistDbContext(name, autoClose); } else { result = new NotEnlistDbContext(name, autoClose); } result.autoClose = autoClose; return(result); }
private static void PopulateSqlServer2000(DbConnection conn, DbProviderFactory factory, DbConfiguration cfg) { if (factory is System.Data.SqlClient.SqlClientFactory) { var connectionStringBuilder = factory.CreateConnectionStringBuilder(); connectionStringBuilder.ConnectionString = cfg.ConnectionString; connectionStringBuilder["Database"] = "master"; var state = conn.State; if (state != ConnectionState.Open) { conn.Open(); } var serverVersion = conn.ServerVersion; if (state != ConnectionState.Open) { conn.Close(); } var version = int.Parse(serverVersion.Substring(0, 2)); if (version < 9) { InitMsSql2000(cfg); } } }
private static DbConnection DbConnection() { //get the proper factory DbProviderFactory factory = DbProviderFactories.GetFactory(Global.Core.DatabaseProvider); DbConnectionStringBuilder dbProviderBuilder = factory.CreateConnectionStringBuilder(); var connString = Global.Core.ConnectionString; //make sure it got created if (dbProviderBuilder != null) { dbProviderBuilder.ConnectionString = connString; //if this provider supports this setting, set it. if (dbProviderBuilder.ContainsKey("MultipleActiveResultSets")) { dbProviderBuilder["MultipleActiveResultSets"] = true; } //use the new modified connection string connString = dbProviderBuilder.ConnectionString; } //create a command of the proper type. DbConnection dbCon = factory.CreateConnection(); //set the connection string if (dbCon != null) { dbCon.ConnectionString = connString; } return(dbCon); }
/// <summary> /// Constructor /// </summary> public SyncQueue() { messageQueue = new Queue(); synchQ = Queue.Synchronized(messageQueue); using (DataTable tbl = DbProviderFactories.GetFactoryClasses()) { foreach (DataRow row in tbl.Rows) { string prov = row[2].ToString(); /*if (prov.IndexOf("SQLite", 0, StringComparison.OrdinalIgnoreCase) != -1 || prov.IndexOf("SqlClient", 0, StringComparison.OrdinalIgnoreCase) != -1 || ) || _provider.Items.Add(prov);*/ if (prov == "CSLibrary.Data.SQLite") { _fact = DbProviderFactories.GetFactory(prov); break; } } } _cnn = _fact.CreateConnection(); _cnn.ConnectionString = databaseName; _cnnstring = _fact.CreateConnectionStringBuilder(); _cnnstring.ConnectionString = databaseName; }
/// <summary> /// Creates query context instance. /// </summary> internal QueryContext(string connectionContextName) { // Get entity works context. var entityWorksContext = EntityWorksContext.GetEntityWorksContext(); // Get connection context. this.ConnectionContext = EntityWorksContext.ConnectionContexts[connectionContextName]; // Set db provider factory. this.DbProviderFactory = this.ConnectionContext.GetSpecificDbProvider(); // Set db string builder. this.DbConnectionStringBuilder = DbProviderFactory.CreateConnectionStringBuilder(); // Parse connection string to builder. this.DbConnectionStringBuilder.ConnectionString = ConnectionContext.ConnectionString; // Set connection segments. Name = connectionContextName; Database = DbConnectionStringBuilder["Initial Catalog"] as string; Username = DbConnectionStringBuilder["User ID"] as string; Password = DbConnectionStringBuilder["Password"] as string; Hostname = DbConnectionStringBuilder["Data Source"] as string; // Set connection string. ConnectionString = DbConnectionStringBuilder.ConnectionString; // Set default language code. LanguageCode = entityWorksContext.LanguageCode; }
private static string GetDatabaseName() { DbConnectionStringBuilder builder = factory.CreateConnectionStringBuilder(); builder.ConnectionString = connectionStringSettings.ConnectionString; return(builder["Initial Catalog"].ToString()); }
public override DbConnectionStringBuilder CreateConnectionStringBuilder() { var connectionBuilder = DbProviderFactory.CreateConnectionStringBuilder(); AssertNullReference(connectionBuilder); connectionBuilder.ConnectionString = ConnectionString; return(connectionBuilder); }
public TunnelConnection(ITunnelDriver driver, string conns) { m_driver = driver; m_factory = driver.ProviderFactory; m_params = (TunnelConnectionStringBuilder)m_factory.CreateConnectionStringBuilder(); m_params.ConnectionString = conns; m_driver.LoadConnectionParams(m_params); }
public static bool ConnectionStringCompare(DbConnection connection, string connectionString) { DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient"); var first = factory.CreateConnectionStringBuilder(); first.ConnectionString = connection.ConnectionString; var second = factory.CreateConnectionStringBuilder(); second.ConnectionString = connectionString; var result = first["Data Source"].Equals(second["Data Source"]); Console.WriteLine("EquivalentTo " + result.ToString()); return(result); }
public ConnectionStringEditorDlg() { InitializeComponent(); DbProviderFactory factory = DbProviderFactories.GetFactory("MySql.Data.MySqlClient"); builder = factory.CreateConnectionStringBuilder(); connStrProps.SelectedObject = builder; }
public DataTable Execute(string dataSource, object arg) { DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb"); using (DbConnection conn = factory.CreateConnection()) { #region // // Excel用の接続文字列を構築. // // Providerは、Microsoft.ACE.OLEDB.12.0を使用する事。 // (JETドライバを利用するとxlsxを読み込む事が出来ない。) // // Extended Propertiesには、ISAMのバージョン(Excel 12.0)とHDRを指定する。 // (2003までのxlsの場合はExcel 8.0でISAMバージョンを指定する。) // HDRは先頭行をヘッダ情報としてみなすか否かを指定する。 // 先頭行をヘッダ情報としてみなす場合はYESを、そうでない場合はNOを設定。 // // HDR=NOと指定した場合、カラム名はシステム側で自動的に割り振られる。 // (F1, F2, F3.....となる) // #endregion DbConnectionStringBuilder builder = factory.CreateConnectionStringBuilder(); builder["Provider"] = "Microsoft.ACE.OLEDB.12.0"; builder["Data Source"] = dataSource; builder["Extended Properties"] = "Excel 12.0;HDR=YES"; conn.ConnectionString = builder.ToString(); conn.Open(); #region // // SELECT. // // 通常のSQLのように発行できる。その際シート指定は // [Sheet1$]のように行う。範囲を指定することも出来る。[Sheet1$A1:C7] // ------------------------------------------------------------------- // INSERT // // こちらも普通のSQLと同じように発行できる。 // 尚、トランザクションは設定できるが効果は無い。 // (ロールバックを行ってもデータは戻らない。) // // また、INSERT,UPDATEはエクセルを開いた状態でも // 行う事ができる。 // // データの削除は行う事ができない。(制限) // #endregion using (DbCommand command = conn.CreateCommand()) { return(RunSql(command, arg)); } } throw new Exception(); }
public static void ExecuteReader(string connectionString, bool singleRow, string commandText, CommandType commandType, DbExecutionParameters executionParameters, Action <DbDataReader> handleOneRow, params DbParameter[] parameters) { using (var connection = _factory.CreateConnection()) { if (executionParameters != null && executionParameters.ConnectionTimeout.HasValue) { var connectionStringBuilder = _factory.CreateConnectionStringBuilder(); connectionStringBuilder.ConnectionString = connectionString; if (connectionStringBuilder is SqlConnectionStringBuilder) { ((SqlConnectionStringBuilder)connectionStringBuilder).ConnectTimeout = executionParameters.ConnectionTimeout.Value; } else { throw new Exception("Do not support setting ConnectionTimeout on " + connectionStringBuilder.GetType().ToString()); } connectionString = connectionStringBuilder.ToString(); } connection.ConnectionString = connectionString; connection.Open(); var logContext = LogBegin("ExecuteReader", connection, commandText, parameters); try { using (var cmd = _factory.CreateCommand()) { cmd.Connection = connection; cmd.CommandText = commandText; cmd.CommandType = commandType; if (executionParameters != null && executionParameters.CommandTimeout.HasValue) { cmd.CommandTimeout = executionParameters.CommandTimeout.Value; } cmd.Parameters.AddRange(parameters); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { handleOneRow(reader); if (singleRow) { break; } } } } } finally { LogEnd(logContext); } } }
public ConnectionStringEditorDlg() { InitializeComponent(); DbProviderFactory factory = MySqlClientFactory.Instance; builder = factory.CreateConnectionStringBuilder(); connStrProps.SelectedObject = builder; }
public static string GetPGSQLConnectionString(string server, string database, string login, string password, string connectionString = "") { var builder = dbFactory.CreateConnectionStringBuilder(); builder.ConnectionString = connectionString; var srv = server.Split(':'); builder["Server"] = srv[0]; builder["Port"] = srv.Length > 1 ? srv[1] : "5432"; builder["UserID"] = login; builder["Password"] = password; builder["IntegratedSecurity"] = login.IsEmpty() && password.IsEmpty(); if (!database.IsEmpty()) { builder["Database"] = database; } return(builder.ConnectionString); }
//[ConnectionStringORA]Oracle接続用ConnectionString(ODP/ADO共通) private static string ConnectionStringORA(DbProviderFactory factory) { DbConnectionStringBuilder csb = factory.CreateConnectionStringBuilder(); csb.Add("Data Source", "xxx.xxx.xxx.xxx:9999/SID"); csb.Add("User ID", "USERID"); csb.Add("Password", "PASSWORD"); return(csb.ConnectionString); }
protected DbRepository(string connectionStringName = "natrail", int?defaultCommandTimeout = null) { _connString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString; _dbFactory = DbProviderFactories.GetFactory(ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName); DbConnectionStringBuilder connBuilder = _dbFactory.CreateConnectionStringBuilder(); connBuilder.ConnectionString = _connString; _commandTimeout = defaultCommandTimeout ?? _defaultCommandTimeout; }
private DbConnectionStringBuilder GetConnectionStringBuilder() { DbProviderFactory factory = CreateDbProviderFactory(); DbConnectionStringBuilder builder = factory.CreateConnectionStringBuilder(); builder[Keys.DataSource] = DataSourceTextBox != null ? DataSourceTextBox.Text : string.Empty; builder[Keys.Pooling] = true; return(builder); }
/// <summary> /// 接続文字列の設定を行います。 /// </summary> /// <param name="connection">DbConnection オブジェクト。</param> /// <param name="providerFactory">DbProviderFactory オブジェクト。</param> /// <param name="connectionValues">接続文字列。</param> public static void SetConnectionString(this DbConnection connection, DbProviderFactory providerFactory, Dictionary <string, string> connectionValues) { var builder = providerFactory.CreateConnectionStringBuilder(); foreach (KeyValuePair <string, string> config in connectionValues) { builder[config.Key] = config.Value; } connection.ConnectionString = builder.ConnectionString; }
private void db_connect(string dbfilename) { //if (System.IO.File.Exists(dbfilename)) System.IO.File.Delete(dbfilename); makeProvider(); _dbfact = DbProviderFactories.GetFactory("System.Data.SQLite"); _dbcon = _dbfact.CreateConnection(); _dbcon.ConnectionString = "Data Source=" + dbfilename + ";Pooling=true;FailIfMissing=false"; _dbconstring = _dbfact.CreateConnectionStringBuilder(); _dbconstring.ConnectionString = "Data Source=" + dbfilename + ";Pooling=true;FailIfMissing=false"; _dbcon.Open(); }
public DbConnectionStringBuilder GetConnectionStringBuilder(string connectionString = null) { var builder = _dbProviderFactory.CreateConnectionStringBuilder(); if (builder != null && !string.IsNullOrWhiteSpace(connectionString)) { builder.ConnectionString = connectionString; } return(builder); }
public ConnectDialog() { InitializeComponent(); factory = DbProviderFactories.GetFactory("MySql.Data.MySqlClient"); if (factory == null) { throw new Exception("MySql Data Provider is not correctly registered"); } connectionStringBuilder = factory.CreateConnectionStringBuilder(); connectionProperties.SelectedObject = connectionStringBuilder; }
/// <summary> /// Constructor /// </summary> /// <param name="bufferSize">BufferSize can't excess <c>MaxBufferSize = 2000</c></param> public SyncQueue(uint bufferSize) { messageQueue = new Queue(); synchQ = Queue.Synchronized(messageQueue); _fact = DbProviderFactories.GetFactory("CSLibray.Data.SQLite"); _cnn = _fact.CreateConnection(); _cnn.ConnectionString = databaseName; _cnnstring = _fact.CreateConnectionStringBuilder(); _cnnstring.ConnectionString = databaseName; this.BufferSize = bufferSize; }
private void wpconnprops_ShowFromNext(object sender, EventArgs e) { try { m_builder = m_factory.CreateConnectionStringBuilder(); ctlProperties.SelectedObject = m_builder; } catch (Exception err) { Errors.Report(err); } }
public GenericConnEditor(GenericSqlStoredConnection conn) { InitializeComponent(); m_conn = conn; DbProviderFactory factory = conn.GetFactory(); m_builder = factory.CreateConnectionStringBuilder(); m_builder.ConnectionString = conn.ConnectionString; SelectedObject = m_builder; }
public AdoDotNetConnectionProperties(string providerName) { Debug.Assert(providerName != null); _providerName = providerName; // Create an underlying connection string builder object DbProviderFactory factory = DbProviderFactories.GetFactory(providerName); Debug.Assert(factory != null); _connectionStringBuilder = factory.CreateConnectionStringBuilder(); Debug.Assert(_connectionStringBuilder != null); _connectionStringBuilder.BrowsableConnectionString = false; }
/// <summary> /// Returns a new instance of the provider's class that implements the /// System.Data.Common.DbConnectionStringBuilder class. /// </summary> /// <param name="factory"> /// The System.Data.Common.DbProviderFactory used to create the /// System.Data.Common.DbConnectionStringBuilder. /// </param> /// <param name="connectionString"> /// Connection string associated with the System.Data.Common.DbConnectionStringBuilder. /// </param> /// <returns> /// A new instance of System.Data.Common.DbConnectionStringBuilder. /// </returns> public static DbConnectionStringBuilder CreateConnectionStringBuilder( this DbProviderFactory factory, string connectionString) { if (factory == null) { throw new ArgumentNullException("factory", "factory should not be null."); } DbConnectionStringBuilder builder = factory.CreateConnectionStringBuilder(); builder.ConnectionString = connectionString; return(builder); }