PowerBuilder Connect PostgreSQL Using ODBC
Step 1: Get driver ODBC Postgresql psqlodbc35w.dll from page : https://www.postgresql.org/ftp/odbc/versions/msi/
Step 2: Registry Regedit With Run file .Reg or PowerBuilder Function RegistrySet()
Step 3: Test Connect
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
String ls_db, ls_database, ls_servername, ls_port, ls_user, ls_pass ls_user = "user" ls_pass = "password" ls_database = "database" ls_servername = "servername" ls_port = "port" ls_db = "ODBC DNS" Transaction ltran_conn ltran_conn = Create Transaction Disconnect Using ltran_conn ; RegistrySet("HKEY_CURRENT_USE\Software\ODBC\ODBC.INI\"+ls_db, "AutoStop", RegString!, 'yes') RegistrySet("HKEY_CURRENT_USE\Software\ODBC\ODBC.INI\"+ls_db,"Database",RegString!,ls_database) RegistrySet("HKEY_CURRENT_USE\Software\ODBC\ODBC.INI\"+ls_db,"ServerName",RegString!,ls_servername) RegistrySet("HKEY_CURRENT_USE\Software\ODBC\ODBC.INI\"+ls_db,"Port",RegString!,ls_port) RegistrySet("HKEY_CURRENT_USE\Software\ODBC\ODBC.INI\"+ls_db,"Driver",RegString!,'psqlodbc35w.dll') RegistrySet("HKEY_CURRENT_USE\Software\ODBC\ODBC.INI\ODBC DATA SOURCES",ls_db, RegString!, "PostgreSQL Unicode") // Using ODBC Connect To Postgres ltran_conn.DBMS = "ODBC" ltran_conn.AutoCommit = False ltran_conn.DBParm = "ConnectString='DSN="+ls_db+";UID="+ls_user+";PWD="+ls_pass+"'" Connect Using ltran_conn ; If ltran_conn.SQLCode = -1 Then MessageBox('Warning','Connect Database Error' + ltran_conn.SQLErrText) Else MessageBox('Warning',"Connect Success!") End If Disconnect Using ltran_conn ; |
Find Projects On Github click here
Good Luck!
Why use Registry Set when connecting? Improves the connection?
you can use it directly using PROVIDERSTRING. I’m going to ODBC using DNS instead of having to register by myself, I set by code. If you use dns you don’t need to install driver, just library.dll driver can work. If you use PROVIDERSTRING you are required to install the client driver. This will be easily deployed to the client machine
I got it! Worked out perfectly! Thank you very much, bro.
Have you used the functions of PostgreSQL, LO_Export and LO_Import in a client / server application? When running Lo_export for example, it looks like the file is being created on the server and not on the client machine.
Do you know how to fix this?
I use psql and run normally you can refer to it.
“psql.exe” -h 192.168.1.1 -p 5432 -d mDB -U madmin -c “\lo_export 19135 ‘C://leeImage.png’ “;
h 192.168.1.1 : is the server system IP
-d mDB : the database name
-U madmin : user name
\lo_export : the export function that will create the image at the client system location
C://leeImage.png : The location and the name of the target image from the OID of the image
19135 : this is the OID of the image in you table.
If you save images to database you can use SELECTBLOB and UPDATEBLOB directly in powerbuilder.