MWS.Data.DBWrapper.Connect C# (CSharp) Method

Connect() public method

public Connect ( ) : bool
return bool
		public bool Connect()
		{
			// Check for valid connection string
			if(m_sConnectionString == null || m_sConnectionString.Length == 0)
				throw( new Exception("Invalid database connection string"));

			// Disconnect if already connected
			Disconnect();

			// Get ADONET connection object
			m_oConnection					= GetConnection();
			m_oConnection.ConnectionString	= this.ConnectionString;

			// Implement connection retries
			for(int i=0; i <= m_nRetryConnect; i++)
			{
				try
				{
					m_oConnection.Open();
	
					if(m_oConnection.State	== ConnectionState.Open)
					{
						m_bConnected	= true;
						break;					
					}
				}
				catch
				{
					if(i == m_nRetryConnect)
						throw;
				
					// Wait for 1 second and try again
					Thread.Sleep(1000);				
				}
			}

			// Get command object
			m_oCommand					= m_oConnection.CreateCommand();
			m_oCommand.CommandTimeout	= m_nCommandTimeout;

			return m_bConnected;
		}