Passing Password Automatically to PostgreSLQ db.

9 views
Skip to first unread message

Robert MacMillan

unread,
May 14, 2026, 12:40:31 AM (11 days ago) May 14
to TheDBCommunity
Has to be simple but I cant see how to do it. I have read all the information I can and all I want is at a form level to either pass explicitly the PostgreSQL password once for the day or pass it via the script that runs whenever I open paradox which sets up all the forms etc at the beginning of the day and not be bothered again for the day.

Any assistance would be appreciated.

Thanks.

Mark Bannister

unread,
May 14, 2026, 8:48:51 AM (10 days ago) May 14
to TheDBCommunity

Pretty easy really once you get it right.  Pass an array of string with the correct parameter names and values to the open command.


This code is from Tom Krieg.  It depends on a library level global array of type database.  That can be confusing if you are not used to using arrays like that.  
The command:
    dynDBS[stAlias].open(":" + stAlias + ":",dynServerParams)
is the same as:
    MyDatabaseVar.open (":" + stAlias + ":",dynServerParams)


Library level Var
Var

dynDBS dynarray[] Database ;// Dynarray of databases

endVar


method pgOpenDatabase
(
const stAlias string,   ;// ODBC Alias name,
const stUname string, ;// PostgreSQL User Name
const stPword string, ;// PostgreSQL Password
var stError   string ;// Error message if error occurred.
)
logical
;----------------------------------------------------
;   This method opens a PostgreSQL database
;----------------------------------------

var
dynServerParams dynArray[] string
endVar

;// If database is already open, no need to open it again
if dynDBS.contains(stAlias) then
if dynDBS[stAlias].isAssigned() then
return TRUE
endif
endif

try
dynServerParams.empty()
dynServerParams["Database alias"] = ":" + stAlias + ":"
dynServerParams["USER NAME"]     = stUname
dynServerParams["Password"]  = stPword
if NOT dynDBS[stAlias].open(":" + stAlias + ":",dynServerParams) then
FAIL()
endif
return True
onFail
stError = ErrorStackToString()
return False
endTry

endMethod

Robert MacMillan

unread,
May 18, 2026, 8:23:41 PM (6 days ago) May 18
to TheDBCommunity
Thank you for the assistance Mark. Much appreciated and it provided a direction.

The final solution was quite interesting, well at least to me, and very simple once I got it figured out which took a while.

Within my startup script on the main form what gets opened every day:-

at the top level of the form in open sequence Var Block include

Var

gdb      Database
gs       Session
sPass   String

endVar

in the open method of the form include

else
;// This code executes only for the form

sPass = "######"
  gs.open()
  gs.setAliasPassword("PostgreSQL35W:", sPass)
  gdb.open("PostgreSQL35W")

It now opens a Global Session Type which is persistent until paradox closes. All the other forms and so on treat the database as open and connected. I might not have correctly described it but I had never used the "Session" Type before and it works an absolute treat.

Robert

Robert MacMillan

unread,
May 18, 2026, 9:21:14 PM (6 days ago) May 18
to TheDBCommunity
Sorry forgot to comment that sPass is your password. Put it in there. Could I would think also pass it from a .ini file as well.
Reply all
Reply to author
Forward
0 new messages