How to Display Database Host Name

BCM

Member
We have a Progress application (4GL and database) installed on three machines for development, testing, and production. The logical database name is the same on each machine. How can a 4GL procedure obtain the name of the database host?
 

joey.jeremiah

ProgressTalk Moderator
Staff member
Code:
function getDbHost returns char ( pcLDbName as char ):
 
    define var cParamList   as char no-undo.
    define var cParam       as char no-undo.
 
    define var cHost        as char no-undo.
    define var cPort        as char no-undo.
 
    define var j            as int no-undo.
    define var i            as int no-undo.
 
    assign
        cParamList = dbparam( pcLDbName )
 
    j = num-entries( cParamList, " " ). do i = 1 to j:
 
        cParam = entry( i, cParamList, " " ).
 
        if cParam begins "-H" then
           cHost = substr( cParam, 4 ).
 
        else
        if cParam begins "-S" then
           cPort = substr( cParam, 4 ).
 
    end. /* 1 to j */
 
    if cHost = "" then
       cHost = "localhost".
 
    return cHost + ( if cPort ne "" then ":" + cPort else "" ).
 
end function. /* getDbHost */
 
 
 
message getDbHost( "sports2000" ) view-as alert-box.

Hi BCM :)

Could you please send me a private message I'd like to talk to you if that is possible.

Thanks.
 

BCM

Member
Thank you, Joey. That code does not provide the results I want. Perhaps, I should specify that I would be connecting to the Progress database in multi-user mode via TCP. That code tells me the host name is "localhost" . I want the name of the remote host on which the database is running. This would be easy with SQL Server, Oracle, etc.
The reason I want the remote host name is to provide clear documentation as to which instance of the application the data has come from.

Private message is on the way.
 

Casper

ProgressTalk.com Moderator
Staff member
This slightly modified version works. Delimiter is ',' and not ' '.

Code:
function getDbHost returns char ( pcLDbName as char ):
 
    define var cParamList   as char no-undo.
    define var cParam       as char no-undo.
 
    define var cHost        as char no-undo.
    define var cPort        as char no-undo.
 
    define var j            as int no-undo.
    define var i            as int no-undo.
 
    assign
        cParamList = dbparam( pcLDbName )
 
    j = num-entries( cParamList). do i = 1 to j:
 
        cParam = entry( i, cParamList).
 
        if cParam begins "-H" then
           cHost = substr( cParam, 4 ).
 
        else
        if cParam begins "-S" then
           cPort = substr( cParam, 4 ).
 
    end. /* 1 to j */
 
    if cHost = "" then
       cHost = "localhost".
 
    return cHost + ( if cPort ne "" then ":" + cPort else "" ).
 
end function. /* getDbHost */
 
 
 
message getDbHost( "sports2000" ) view-as alert-box.

Casper
 

Daniel Vanzo

New Member
Hello,
Untested, but if you connect using -H -S parameters, you can obtain the Database Host Name from the _DB.DB-COMM column:

DEF VAR cDbHostName AS CHARACTER NO-UNDO.

cDbHostName = ENTRY(LOOKUP("-H",_DB._DB-COMM, " ") + 1, _DB._DB-COMM, " ").


Regards,

Daniel
 

BCM

Member
Daniel, in our database _DB._DB-COMM is an empty string.

Casper and Joey, thank you very much. It works.

Though I do not like Progress, I have a sincere appreciation and respect for all of you and your thoughtful, helping nature.
 

Casper

ProgressTalk.com Moderator
Staff member
Though I do not like Progress, I have a sincere appreciation and respect for all of you and your thoughtful, helping nature.

Thanks, and I understand your Point of view. From an SQL perspective Progress can be rather obscure :awink:
 
Top