Esempio n. 1
0
 private void _afterDBConnectCallback(DBConnAfterEventArgs args) {
   var e = this.AfterDBConnectEvent;
   if (e != null)
     e(this, args);
 }
    public IDbConnection CreateConnection(String connStr, String workspaceSchema, Action<DBConnBeforeEventArgs> beforeDBConnectCallback, 
                                                                  Action<DBConnAfterEventArgs> afterDBConnectCallback) {
      if (beforeDBConnectCallback != null) {
        var args = new DBConnBeforeEventArgs {
          Cancel = false,
          ConnectionString = connStr
        };
        beforeDBConnectCallback(args);
        if (args.Cancel) return null;
        connStr = args.ConnectionString; 
      }
      IDbConnection result = this._factory.CreateConnection();
      if (!String.IsNullOrEmpty(connStr) && (result != null)) {
        result.ConnectionString = connStr;
        try {
          result.Open();
        } catch (ThreadAbortException) {
          throw;
        } catch (Exception ex) {
          throw new EBioDBConnectionError("Ошибка соединения с базой данных. Сообщение сервера: " + ex.Message, ex);
        }
        if (!String.IsNullOrEmpty(workspaceSchema)) {
          SQLCmd.ExecuteScript(result, "ALTER SESSION SET CURRENT_SCHEMA=" + workspaceSchema.ToUpper(), null, 60);
        }
        if (afterDBConnectCallback != null) {
          var args = new DBConnAfterEventArgs {
            Connection = result
          };
          afterDBConnectCallback(args);
        }

      }
      return result;
    }