public void OpenConnection(String conName)
        {
            try
            {
                if (disconnection.IsNotNull())
                {
                    if (disconnection.State == ConnectionState.Open)
                    {
                        disconnection.Close();
                    }
                    disconnection = null;
                }
                else
                {
                    if (conName.Trim().Length == 0)
                    {
                        switch (ProviderType)
                        {
                            case Util.ConnectionLibrary.SQlClient:
                                disconnection = new SqlConnection();
                                break;
                            case Util.ConnectionLibrary.Oledb:
                                disconnection = new OleDbConnection();
                                break;
                            case Util.ConnectionLibrary.ODBC:
                                disconnection = new OdbcConnection();
                                break;
                        }
                        if (disconnection.IsNotNull()) disconnection.ConnectionString = defaultConnectionString;
                    }
                    else
                    {
                        // Find out the provider and Conncetion String
                        var providerType = new Util.ConnectionLibrary();
                        String connectionString = String.Empty;

                        if (mblnIsConnectionString.IsFalse())
                        {
                            if (ProvideConnectionInfo(conName, ref connectionString, ref providerType).IsFalse())
                            {
                                throw new Exception("Application Server is not configured properly\n.There is no link between Application Server and Database Server. Please configure the Application Server properly or ask your MIS Officer or technical person to do so.");
                            }
                        }
                        else
                        {
                            connectionString = defaultConnectionString;
                        }

                        switch (providerType)
                        {
                            case Util.ConnectionLibrary.SQlClient:
                                disconnection = new SqlConnection();
                                break;
                            case Util.ConnectionLibrary.Oledb:
                                disconnection = new OleDbConnection();
                                break;
                            case Util.ConnectionLibrary.ODBC:
                                disconnection = new OdbcConnection();
                                break;
                        }
                        if (disconnection.IsNotNull()) disconnection.ConnectionString = connectionString;
                    }
                }

                if (disconnection.IsNotNull()) disconnection.Open();
                mblnTransactionStart = false;
            }
            catch (OleDbException oleDbEx)
            {
                throw (oleDbEx);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Exemple #2
0
 public CommandExecutor(IDbTransaction transaction, Util.ConnectionLibrary ProviderType)
 {
     this.transaction = transaction;
     DataAccessHelper.ProviderType = ProviderType;
 }
 private void Initailize(String conString, Util.ConnectionLibrary eType)
 {
     ProviderType = eType;
     defaultConnectionString = conString;
 }