public static void ClearPool(MySqlConnectionStringBuilder settings) { Debug.Assert(settings != null); string text; try { text = GetKey(settings); } catch (MySqlException) { // Cannot retrieve windows identity for IntegratedSecurity=true // This can be ignored. return; } ClearPoolByText(text); }
public MySqlPool(MySqlConnectionStringBuilder settings) { minSize = settings.MinimumPoolSize; maxSize = settings.MaximumPoolSize; available = (int)maxSize; autoEvent = new AutoResetEvent(false); if (minSize > maxSize) minSize = maxSize; this.settings = settings; inUsePool = new List<Driver>((int)maxSize); idlePool = new Queue<Driver>((int)maxSize); // prepopulate the idle pool to minSize for (int i = 0; i < minSize; i++) EnqueueIdle(CreateNewPooledConnection()); }
protected override void DbDeleteDatabase(DbConnection connection, int? commandTimeout, StoreItemCollection storeItemCollection) { if (connection == null) throw new ArgumentNullException("connection"); MySqlConnection conn = connection as MySqlConnection; if (conn == null) throw new ArgumentException(Resources.ConnectionMustBeOfTypeMySqlConnection, "connection"); MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(); builder.ConnectionString = conn.ConnectionString; string dbName = builder.Database; builder.Database = null; using (MySqlConnection c = new MySqlConnection(builder.ConnectionString)) { c.Open(); MySqlCommand cmd = new MySqlCommand(String.Format("DROP DATABASE IF EXISTS `{0}`", dbName), c); if (commandTimeout.HasValue) cmd.CommandTimeout = commandTimeout.Value; cmd.ExecuteNonQuery(); } }
protected override bool DbDatabaseExists(DbConnection connection, int? commandTimeout, StoreItemCollection storeItemCollection) { if (connection == null) throw new ArgumentNullException("connection"); MySqlConnection conn = connection as MySqlConnection; if (conn == null) throw new ArgumentException(Resources.ConnectionMustBeOfTypeMySqlConnection, "connection"); MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(); builder.ConnectionString = conn.ConnectionString; string dbName = builder.Database; builder.Database = null; using (MySqlConnection c = new MySqlConnection(builder.ConnectionString)) { c.Open(); DataTable table = c.GetSchema("Databases", new string[] { dbName }); if (table != null && table.Rows.Count == 1) return true; return false; } }
protected override void DbCreateDatabase(DbConnection connection, int? commandTimeout, StoreItemCollection storeItemCollection) { if (connection == null) throw new ArgumentNullException("connection"); MySqlConnection conn = connection as MySqlConnection; if (conn == null) throw new ArgumentException(Resources.ConnectionMustBeOfTypeMySqlConnection, "connection"); string query = DbCreateDatabaseScript(null, storeItemCollection); using (MySqlConnection c = new MySqlConnection()) { MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder(conn.ConnectionString); string dbName = sb.Database; sb.Database = null; c.ConnectionString = sb.ConnectionString; c.Open(); string fullQuery = String.Format("CREATE DATABASE `{0}`; USE `{0}`; {1}", dbName, query); MySqlScript s = new MySqlScript(c, fullQuery); s.Execute(); } }
public TracingDriver(MySqlConnectionStringBuilder settings) : base(settings) { driverId = Interlocked.Increment(ref driverCounter); }
public void CancelQuery(int timeout) { MySqlConnectionStringBuilder cb = new MySqlConnectionStringBuilder( Settings.ConnectionString); cb.Pooling = false; cb.AutoEnlist = false; cb.ConnectionTimeout = (uint)timeout; using (MySqlConnection c = new MySqlConnection(cb.ConnectionString)) { c.isKillQueryConnection = true; c.Open(); string commandText = "KILL QUERY " + ServerThread; MySqlCommand cmd = new MySqlCommand(commandText, c); cmd.CommandTimeout = timeout; cmd.ExecuteNonQuery(); } }
/// <include file='docs/MySqlConnection.xml' path='docs/DefaultCtor/*'/> public MySqlConnection() { //TODO: add event data to StateChange docs settings = new MySqlConnectionStringBuilder(); database = String.Empty; }
public static Driver Create(MySqlConnectionStringBuilder settings) { Driver d = null; #if !CF try { if (MySqlTrace.QueryAnalysisEnabled || settings.Logging || settings.UseUsageAdvisor) d = new TracingDriver(settings); } catch (TypeInitializationException ex) { if (!(ex.InnerException is SecurityException)) throw ex; //Only rethrow if InnerException is not a SecurityException. If it is a SecurityException then //we couldn't initialize MySqlTrace because we don't have unmanaged code permissions. } #endif if (d == null) d = new Driver(settings); d.Open(); return d; }
public Driver(MySqlConnectionStringBuilder settings) { encoding = Encoding.GetEncoding(1252); if (encoding == null) throw new MySqlException(Resources.DefaultEncodingNotFound); connectionString = settings; serverCharSet = "latin1"; serverCharSetIndex = -1; maxPacketSize = 1024; handler = new NativeDriver(this); }
internal void Serialize(MySqlPacket packet, bool binary, MySqlConnectionStringBuilder settings) { if (!binary && (paramValue == null || paramValue == DBNull.Value)) packet.WriteStringNoNull("NULL"); else { if (ValueObject.MySqlDbType == MySqlDbType.Guid) { MySqlGuid g = (MySqlGuid)ValueObject; g.OldGuids = settings.OldGuids; valueObject = g; } ValueObject.WriteValue(packet, binary, paramValue, size); } }
public static Driver Create(MySqlConnectionStringBuilder settings) { Driver d = new Driver(settings); d.Open(); return d; }
private static string GetKey(MySqlConnectionStringBuilder settings) { string key = settings.ConnectionString; if (settings.IntegratedSecurity && !settings.ConnectionReset) { try { // Append SID to the connection string to generate a key // With Integrated security different Windows users with the same // connection string may be mapped to different MySQL accounts. System.Security.Principal.WindowsIdentity id = System.Security.Principal.WindowsIdentity.GetCurrent(); key += ";" + id.User; } catch (System.Security.SecurityException ex) { // Documentation for WindowsIdentity.GetCurrent() states // SecurityException can be thrown. In this case the // connection can only be pooled if reset is done. throw new MySqlException(ResourceStrings.NoWindowsIdentity, ex); } } return key; }
public static MySqlPool GetPool(MySqlConnectionStringBuilder settings) { string text = GetKey(settings); lock (pools.SyncRoot) { MySqlPool pool = (pools[text] as MySqlPool); if (pool == null) { pool = new MySqlPool(settings); pools.Add(text, pool); } else pool.Settings = settings; return pool; } }