Ejemplo n.º 1
0
        public static bool SetConnIDs(User user, bool isTest)
        {
            if (isTest)
            {
                // Use default connections when debugging
                user.OCConnID = idTestOC;
                user.NPConnID = idTestNP;
                user.SHConnID = idTestSH; // Use OC ID
                user.SLConnID = idTestSL; // Use OC ID
                return(true);
            }
            DBConnect connection = new DBConnect();

            if (!connection.Connect(ConnectionsMgr.GetAdminConnInfo()))
            {
                return(false);
            }
            try
            {
                using (var res = connection.Select(new[] { columnOCConnID, columnNPConnID, columnSHConnID, columnSLConnID }, tableConnectionIDInfo, string.Format("WHERE {0}='{1}'", columnCustomer, user.Customer)))
                {
                    if (!res.Read())
                    {
                        // No info for customer?
                        ProgramLog.LogError(user.UserName, user.Customer, "EDIO", "ConnectionsMgr", "SetConnIDs", string.Format("Unable to find connection info in {0} for customer {1}", tableConnectionIDInfo, user.Customer));
                        connection.Close();
                        return(false);
                    }
                    user.OCConnID = res.Field(0);
                    user.NPConnID = res.Field(1);
                    user.SHConnID = res.Field(2);
                    user.SLConnID = res.Field(3);
                }
                connection.Close();
                return(true);
            }
            catch (Exception e)
            {
                ProgramLog.LogError(user, "ConnectionsMgr", "SetConnIDs", e.Message);
                connection.Close();
                return(false);
            }
        }
Ejemplo n.º 2
0
        private static DatabaseInfo _GetConnInfo(User user, string connID, string database = "")
        {
            DatabaseInfo dbInfo = new DatabaseInfo();

            DBConnect connection = new DBConnect();

            if (!connection.Connect(ConnectionsMgr.GetAdminConnInfo()))
            {
                ProgramLog.LogError(user, "ConnectionInfo", "_GetConnInfo", "Unable to connect to admin database.");
                return(dbInfo);
            }

            using (var res = connection.Select(new[] { columnServer, columnPort, columnIsTest }, tableAllPorts, string.Format("WHERE {0}='{1}'", columnConnectID, connID.SQLEscape())))
            {
                if (!res.Read())
                {
                    ProgramLog.LogError(user, "ConnectionInfo", "_GetConnInfo", string.Format("Unable to find info in table \"{0}\" for connection ID \"{1}\".", tableConnectionIDInfo, connID.SQLEscape()));
                    connection.Close();
                    return(dbInfo);
                }
                dbInfo.Server = res.Field(0);
                dbInfo.Port   = (int)res.Field2(1);
                dbInfo.IsTest = (int)res.Field2(2) != 0;
            }
            connection.Close();

            dbInfo.Id       = connID;
            dbInfo.Database = string.IsNullOrWhiteSpace(database) ? databaseHome : database;
            dbInfo.Driver   = _DefaultDriver;
            if (cred.ContainsKey(dbInfo.Id))
            {
                dbInfo.Username = cred[dbInfo.Id].UserName;
                dbInfo.Password = cred[dbInfo.Id].Password;
            }
            else
            {
                dbInfo.Username = defaultCred.UserName;
                dbInfo.Password = defaultCred.Password;
            }
            return(dbInfo);
        }