cancel
Showing results for 
Search instead for 
Did you mean: 

PB Newbie - INI file

Former Member
0 Kudos


Hi PB gurus!

How does an an ini file work to store/use database, server name, etc.?

Thanks in advance,

Accepted Solutions (1)

Accepted Solutions (1)

arnd_schmidt
Active Contributor
0 Kudos

Create a new target of type "Template application".

This will generate some basic code and classes.

The generated connection service class shows how to read connection properties from various sources.

hth

Arnd

Former Member
0 Kudos

Thank  you! I'm getting to like PB already!

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Roland/Cris,

Another issue here. I get the source from Roland regarding the Encryption and decryption.  No issue on that, my problem is in the setprofilestring and profilestring.  I cannot get the exact value from the ini.  Let us take this as sample, I encrypted a password let say the encrypted value is "xxdal aldkfj   " and it was saved just same (without the double quote).  But when I try to login again I will use profilestring to get that password and I only got "xxdal" remaining value was not being captured making it as invalid password when I tried to decrypt.  Is this a bug in 12.6 build 3506?  Should I go for build 4088?

Regards,

Elena

Former Member
0 Kudos

Hi Elena;

1)  The ProfileString () method should read everything on that line for the key you are seeking. I have bee using this technique succesfully with my framework & encrypted values for decades.

2) FWIW: Build 3506 is quite buggy. However, I do not think that its disabled something like the ProfileString () method that has been working in PB since its inception.

Also, make sure that you created the INI file in Unicode format and not ANSI.

Can you post your INI file contents here and the logic you use to read this value?

Regards ... Chris

Former Member
0 Kudos

If you open the INI file in an editor, what is actually in that setting?

If you look at the encrypted value in the debugger before you write it to the INI file, what characters are where you are indicating spaces? If it was newlines or something like that, that would probably cause problems with the underlying Windows APIs anyways, and you would have to escape them somehow.

Former Member
0 Kudos

Initially the file was saved in ANSI format but even if I changed it to Unicode it's still the same.  Actually profilestring and setprofilestring is not disabled, I can get the value but not complete.  Like Dan was saying I noticed that if I put the cursor on encrypted value I noticed that there are spaces or not sure if what char but there's a place where I moved the cursor but it's not moving and that is where the value is being cut for both profilestring and set profile string.

ex. 1jlajskj*asdka (let say the * is the place where my cursor not moving)

when use profile string I can only get the value 1jlajskj* and asdka will not be included.  so if I decrypt the password it is already wrong as I need the whole string.  and if I change the password and use setprofilestring it's the same

ex. new password is 11112323xxx

after setprofile string the value becomes 11112323xxxasdka - the asdka is from the old password which was not included when you use profilestring.  I also tried to put the blank value first before setting the encrypted password but cannot remove the asdka.  The problem is the value of the encrypted password comes from the code.

Sorry can't give the exact value of ini as I can't paste it here.  By the way in the code the secretkey is fixed as "secretkey" string.  I changed that, and get the secretkey value from an ini coz they want to change it when needed.

Regards,

Elena

Former Member
0 Kudos
Former Member
0 Kudos

Hi Dan,

Actually that was my problem coz the encrypted value comes from the code and not manipulated by me.  I used AES 256 as encryption method.

Regards,

Elena

Former Member
0 Kudos

Hi Elena;

  Can try adding this as THE 1st line in your INI file ...

0xFEFF

Regards ... Chris

ricardojasso
Participant
0 Kudos

The encrypted password doesn't seem to be text friendly. Try converting it to base64binary before storing it to the ini file and back to binary when reading it before decrypting it and using it to connect to the database.

Former Member
0 Kudos

Hi Ricardo;

  Great suggestion!  

  The other alternative Elena is to download my framework and use the two global functions to encrypt & decrypt. The two function objects are independent of the framework and can be used in your application "as is". They also support a "seed key" approach in their design. The encrypted string will be INI friendly. 

FYI:: My framework also has Base64 support in it as well. For more information, click here!

Regards ... Chris

arnd_schmidt
Active Contributor
0 Kudos

Take a look at Roland's crypto library and example => Topwiz Software - Crypto

You can convert the "string"  to "normal characters" via of_encode64 ()  before your write it to the INI File and decode this string via of_decode64() after you read it from the INI File.

hth

Arnd

Former Member
0 Kudos

If one of the things you need to store in the INI file is a password for access to the DB, you should probably not store it as clear text, but encrypt it with a reversible encryption.

Former Member
0 Kudos

Hi Ryan;

  In addition to what Roland said, there is also the Get/SetProfileInt() methods as well to assist you in interoperating with INI files. The key thing to remember when creating INI files with newer PB & O/S versions is that they are expected to be Unicode. So if your using Notepad for example, make sure when you do a SaveAs that you select the Unicode format in the save dialog.

  For a good example of INI file use, have a look at my example OrderEntry application built from the STD Foundation Class framework. The entire PB framework is INI file driven. The INI approach works for native PB, .Net, Web & Mobile deployed applications from PowerBuilder.

FYI:  OrderEntry

HTH

Regards ... Chris

Former Member
0 Kudos

Very helpful! Thanks, Chris!

Former Member
0 Kudos

Use the ProfileString function to retrieve values from the file and SetProfileString to set values.

Former Member
0 Kudos

Thank you, Roland!