i am trying to access .ini file where stored the db information for powerbuilder

732 Views Asked by At

When I run this code I get default value as "sorry" instead of original value. Here is my code:

sle_dbms.text = ProfileString( "C:\database.ini" , &
                                "DBMS" , "DBMS" , "Sorry" )
sle_database.text = ProfileString( "C:\database.ini" , &
                                "DBMS" , "ServerName" , "Sorry" )
sle_name.text = ProfileString( "C:\database.ini" , &
                               "DBMS" , "LogId" , "Sorry" )

Please help me to fix this query...

1

There are 1 best solutions below

0
Rich Bianco On

You didn't provide enough information to answer conclusively. Rather than leave this unanswered, will provide extra information so that it can be answered and help others with same challenge.

Scenario 1

INI file named c:\database.ini does not exist

Result:

All three calls to the ProfileString function return the default 'Sorry' because there was no ini file

Scenario 2:

INI File exists with the contents like:

[DBMS]
DBMS=Hello
DSN=World
ServerName=Matrix
LoginId=jdoe
DebugLevel=1

Result: Third ProfileString returns default because 'LogId' not in INI file

// These find respective file, section, key and therefore return the ini value 
ProfileString("C:\database.ini", "DBMS", "DBMS"  "Sorry") will return 'Hello'
ProfileString("C:\database.ini", "DBMS", "ServerName", "Sorry") will return 'Matrix'

// File & section found but key 'LoginId' was misspelled so returns default 'Sorry'
ProfileString( "C:\database.ini","DBMS", "LogUserId", "Sorry") will return 'Sorry'