Beispiel #1
0
        public static ConnectionParams getEffectiveConnectionParams(ConnectionParams fromRequest, ref NoPwdConnectionParams resultConnectionReference)
        {
            ConnectionParams cp = brokerConf.defaultConnection;

            if (!string.IsNullOrEmpty(fromRequest?.CompanyDB))               // Request contains connection params
            {
                if (brokerConf.connectionConfigFromCaller)
                {
                    cp = fromRequest;
                }
                else
                {
                    throw new Exception("SQL Broker is configured to reject connection parameters from clients. Only Profile name is allowed.");
                }
            }
            if (!string.IsNullOrEmpty(fromRequest?.Profile))               // Request can contain connection profile and it overrides everything else
            {
                ConnectionParams pcp = ConnectionParams.GetConnectionProfile(fromRequest?.Profile);
                if (pcp != null)
                {
                    cp = pcp;
                    //With the following logic, it is possible that the system admin intentionally leaves out user names and passords,
                    //and the the application programmer has to take measures to make a form where the user can enter these users names
                    //and corresponding passords.
                    //The simplest way is just to leave out the SAP B1 password. Of course, don't use manager as the preconfigured
                    //SAP user then.
                    if (string.IsNullOrEmpty(cp.Password) && !string.IsNullOrEmpty(fromRequest.Password))
                    {
                        cp.Password = fromRequest.Password;
                    }
                    if (string.IsNullOrEmpty(cp.UserName) && !string.IsNullOrEmpty(fromRequest.UserName))
                    {
                        cp.UserName = fromRequest.UserName;
                    }
                    if (string.IsNullOrEmpty(cp.DbUserName) && !string.IsNullOrEmpty(fromRequest.DbUserName))
                    {
                        cp.DbUserName = fromRequest.DbUserName;
                    }
                    if (string.IsNullOrEmpty(cp.DbPassword) && !string.IsNullOrEmpty(fromRequest.DbPassword))
                    {
                        cp.DbPassword = fromRequest.DbPassword;
                    }
                }
            }
            if (cp == null)
            {
                throw new Exception("No connection parameters are configured or sent by client");
            }
            else               //These are the effective connection parameters for reference to the caller
            {
                resultConnectionReference = new NoPwdConnectionParams(cp);
            }
            return(cp);
        }
Beispiel #2
0
 public SQLBrokerError(string message, Exception innerException = null,
                       ConnectionParams connection = null, SQLResult sqlResult = null, BOResult boResult = null) : base(message, innerException)
 {
     config          = SAPB1.brokerConf;
     this.boResult   = boResult;
     this.sqlResult  = sqlResult;
     this.connection = new NoPwdConnectionParams(connection);
     if (this.connection == null && boResult?.connection != null)
     {
         this.connection = boResult?.connection;
     }
     if (this.connection == null && sqlResult?.connection != null)
     {
         this.connection = sqlResult?.connection;
     }
 }