Пример #1
0
        public static MySqlInternalConnection GetConnection(MySqlConnectionString settings)
        {
            // make sure the manager is initialized
            if (MySqlPoolManager.pools == null)
            {
                MySqlPoolManager.Initialize();
            }

            string text = settings.GetConnectionString();

            lock (pools.SyncRoot)
            {
                MySqlPool pool;
                if (!pools.Contains(text))
                {
                    pool = new MySqlPool(settings);
                    pools.Add(text, pool);
                }
                else
                {
                    pool = (pools[text] as MySqlPool);
                }

                return(pool.GetConnection());
            }
        }
Пример #2
0
		public MySqlPool(MySqlConnectionString settings)
		{
			minSize = settings.MinPoolSize;
			maxSize = settings.MaxPoolSize;
			this.settings = settings;
			inUsePool =new ArrayList();
			idlePool = new ArrayList( settings.MinPoolSize );

			// prepopulate the idle pool to minSize
			for (int i=0; i < minSize; i++) 
				CreateNewPooledConnection();
		}
Пример #3
0
        public MySqlPool(MySqlConnectionString settings)
        {
            minSize       = settings.MinPoolSize;
            maxSize       = settings.MaxPoolSize;
            this.settings = settings;
            inUsePool     = new ArrayList();
            idlePool      = new ArrayList(settings.MinPoolSize);

            // prepopulate the idle pool to minSize
            for (int i = 0; i < minSize; i++)
            {
                CreateNewPooledConnection();
            }
        }
Пример #4
0
        public void Open(MySqlConnectionString settings)
        {
            // connect to one of our specified hosts
            try
            {
                StreamCreator sc = new StreamCreator(settings.Server, settings.Port, settings.PipeName);
                stream = sc.GetStream(settings.ConnectionTimeout);
            }
            catch (Exception ex)
            {
                throw new MySqlException("Unable to connect to any of the specified MySQL hosts", ex);
            }

            if (stream == null)
            {
                throw new MySqlException("Unable to connect to any of the specified MySQL hosts");
            }

            writer = new BufferedStream(stream);
            // read off the welcome packet and parse out it's values
            Packet packet = ReadPacket();

            protocol       = packet.ReadByte();
            versionString  = packet.ReadString();
            serverVersion  = DBVersion.Parse(versionString);
            threadID       = (uint)packet.ReadInteger(4);
            encryptionSeed = packet.ReadString();

            // read in Server capabilities if they are provided
            serverCaps = 0;
            if (packet.HasMoreData)
            {
                serverCaps = (int)packet.ReadInteger(2);
            }

            Authenticate(settings.UserId, settings.Password, settings.UseCompression);

            // if we are using compression, then we use our CompressedStream class
            // to hide the ugliness of managing the compression
            if (settings.UseCompression)
            {
                stream = new CompressedStream(stream);
                writer = new BufferedStream(stream);
            }

            isOpen = true;
        }
Пример #5
0
		public void Open( MySqlConnectionString settings )
		{
			// connect to one of our specified hosts
			try 
			{
				StreamCreator sc = new StreamCreator( settings.Server, settings.Port, settings.PipeName );
				stream = sc.GetStream( settings.ConnectionTimeout );
			}
			catch (Exception ex)
			{
				throw new MySqlException("Unable to connect to any of the specified MySQL hosts", ex);
			}

			if (stream == null) 
				throw new MySqlException("Unable to connect to any of the specified MySQL hosts");

			writer = new BufferedStream( stream );
			// read off the welcome packet and parse out it's values
			Packet packet = ReadPacket();
			protocol = packet.ReadByte();
			versionString = packet.ReadString();
			serverVersion = DBVersion.Parse( versionString );
			threadID = (uint)packet.ReadInteger(4);
			encryptionSeed = packet.ReadString();

			// read in Server capabilities if they are provided
			serverCaps = 0;
			if (packet.HasMoreData)
				serverCaps = (int)packet.ReadInteger(2);

			Authenticate( settings.UserId, settings.Password, settings.UseCompression );

			// if we are using compression, then we use our CompressedStream class
			// to hide the ugliness of managing the compression
			if (settings.UseCompression)
			{
				stream = new CompressedStream( stream );
				writer = new BufferedStream( stream );
			}

			isOpen = true;
		}
		public static MySqlInternalConnection GetConnection( MySqlConnectionString settings ) 
		{
			// make sure the manager is initialized
			if (MySqlPoolManager.pools == null)
				MySqlPoolManager.Initialize();

			string text = settings.GetConnectionString();

			lock( pools.SyncRoot ) 
			{
				MySqlPool pool;
				if (!pools.Contains( text )) 
				{
					pool = new MySqlPool( settings );
					pools.Add( text, pool );
				}
				else 
				{
					pool = (pools[text] as MySqlPool);
				}

				return pool.GetConnection();
			}
		}
		public MySqlInternalConnection( MySqlConnectionString connectString )
		{
			settings = connectString;
			serverVariablesSet = false;
		}
Пример #8
0
		// Have a constructor that takes a connection string.
		/// <summary>
		/// Creates a new connection using the specified connection string.
		/// </summary>
		/// <param name="connectString"></param>
		public MySqlConnection(string connectString)
		{
			settings = new MySqlConnectionString(connectString);
		}
Пример #9
0
 public MySqlInternalConnection(MySqlConnectionString connectString)
 {
     settings           = connectString;
     serverVariablesSet = false;
 }
Пример #10
0
		/// <summary>
		/// Creates a new connection
		/// </summary>
		/// <param name="container"></param>
		public MySqlConnection(System.ComponentModel.IContainer container)
		{
			settings = new MySqlConnectionString();
		}
Пример #11
0
		/// <summary>
		/// Creates a new connection
		/// </summary>
		public MySqlConnection()
		{
			settings = new MySqlConnectionString("server=localhost");
		}
Пример #12
0
 // Have a constructor that takes a connection string.
 /// <summary>
 /// Creates a new connection using the specified connection string.
 /// </summary>
 /// <param name="connectString"></param>
 public MySqlConnection(string connectString)
 {
     settings = new MySqlConnectionString(connectString);
 }
Пример #13
0
 /// <summary>
 /// Creates a new connection
 /// </summary>
 /// <param name="container"></param>
 public MySqlConnection(System.ComponentModel.IContainer container)
 {
     settings = new MySqlConnectionString();
 }
Пример #14
0
 /// <summary>
 /// Creates a new connection
 /// </summary>
 public MySqlConnection()
 {
     settings = new MySqlConnectionString("server=localhost");
 }