Connecting MS Access to PostgreSQL Server - postgresql

I'm having trouble with connecting to our postgres server. I was given the code used to connect ms access to our SQL Server. It shall be DSN-less, I have installed an ODBC-driver and now I'm stuck finding the correct connection string to write in access' vba code.
I know it has to be somewhat like this:
stConnect = "ODBC;Driver={PostgreSQL UNICODE};Data Provider=pgsqlODBC;hostaddr=[IP-adress];Port=61000;dbname=TE_TestFirst;user=admin;password=testtest;"
Or maybe like this:
stConnect = "ODBC;Driver={PostgreSQL UNICODE};Data Provider=pgsqlODBC;SERVER=[IP-adress];PORT=61000;DATABASE=TE_TestFirst;UID=admin;PWD=testtest;"
I have read that 64Bit-Pcs need to have been given the "Data Provider". Yet nothing works except the DSN version which we don't want. I've copied countless connection string from various sides, maybe I'm overseeing something?
I look forward to your replies and thank you in advance.
Puddingloeffel

I have found a way to create a User-DSN within a MS Access module, which then I use to connect to the server. It is no very pretty code, but it works. For those who look for a similar solution:
'Creating User DSN
strAttributes = "Description=I did this myself" & Chr(13) & "Server=[Servername/ID]" & Chr(13) & "Database=TE_TestFirst" & Chr(13) & "Username=admin" & Chr(13) & "Password=***" & Chr(13) & "Port=61000"
DBEngine.RegisterDatabase "DSNnew", "PostgreSQL Unicode", True, strAttributes
MsgBox "DSN has been created", vbInformation
Connection String
stConnect = "ODBC;DSN=DSNnew;Server=[IP-adress];Port=61000;Database=TE_TestFirst;Uid=admin;Pwd=****;"
As you can see the information is embedded twice, which I really don't like but for the moment it is okay. You can check your created DSN with the ODBC Administrator.
You can find the original code here
Also this code is the way we get the tables from the server to MS Access. Although the example is about SQL Server, it works fine with PostgreSQL as well! (As I see now this side also provides a solution about creating DSNs)

I haven't been able to solve the matter with a connection string that is DSN-less, but with a DSN file like #Erik van Asmuth and #krish KM said.
The DSN file is located in my Documents folder (ODBC Administrator saved it automatically in this folder. You can move it anywhere, but then you have to write the path instead of the file name)
I open it via VBA Code in MS Access with the following connection String:
stConnect = "ODBC;FILEDSN=PGUnicode32;Server=[IP-adress];Port=61000;Database=TE_TestFirst;Uid=admin;Pwd=****;"
Access got a connection and loads the table TE-TestFirst. Thank you guys again. I will now try to connect via connection string without the file

In the end we did the following:
Using connection string "PostgreSQL Unicode(x32)" written like shown above + using a different script to connect to
It now works fine and DSN-less :)

Something like this:
stConnect = "Driver={PostgreSQL Unicode(x64)};Servername=dbtest;Port=5432;UID=postgres;Database=postgres;Password=****";

Related

Tableau Command Line - Refresh datasource

I have a Tableau Workbook which connects to server-side data source. Researching online it seems the accepted way to refresh this is something like
tabcmd refreshextracts -–datasource “Number of Goals”.
My datasource is named "aggregated usage table". I have tried basically copying what I saw online, using
tabcmd refreshextracts -–datasource “aggregated usage table”, and receive the error message "*** Item not found". Clearly I am not correctly identifying my data source.
Can someone help me determine the correct syntax for this?
The O/E is Linux. Thank you!
Longshot, but something looks off about your dashes...
When I copy yours vs mine:
-– vs --
When I put yours into word and enlarge they look even weirder. Sometimes this can happen if copying and pasting from the web to import into your script.
Try copying and pasting my command and see if it works:
tabcmd refreshextracts --datasource “aggregated usage table”

LibreOffice BASIC : Connect to PostgreSQL

I've created a PostgreSQL connection File using LibreOffice Base (6.1) and I can run SQL Queries in there just fine but I was wondering if it's possible to use this Base connection in a LibreOffice BASIC function.
I know you can use JDBC connections for MySQL
mysql://hostname:port/database_name
But I'm hoping there's a way to use the Base File seeing as it works so well
I've been trying to find documentation on this online but I am struggling to find anything that bridges the gap between BASIC and Base.
I've found the answer, the solution was to use createUnoService and that allows you to specify the name of the odb that was setup in Base.
oService = createUnoService("com.sun.star.sdb.DatabaseContext")
oBase = oService.getByName("basePostgreSQL")
oConn = oBase.getConnection("","")
oQuery = oConn.createStatement()
oSql = "select col from table"
oResult = oQuery.executeQuery(oSql)
while oResult.next()
msgBox oResult.getString(1)
wend
oConn.close()

How to decode a string in Visual Basic 6

I'm trying to read .DB (Paradox 5) file within my Visual Basic 6.
Everything's OK except encoding/charset. It shows as Iieiei 75a instead of cyrillic string.
This is my ODBC Connection string:
Driver={Microsoft Paradox Driver (*.db )};DriverID=538;Fil=Paradox 4.X;DataCodePage=ANSI;BDE=2;CollatingSequence=ASCII;AutoTranslate=No;DBQ=C:\Database;DefaultDir=C:\Database
Please note that software like Borland Database Desktop shows this strings without any problems. Also everything is fine in another PC.
I set following settings via regedit, by it doesn't help:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Xbase]
"DataCodePage"="ANSI"
"BDE"=dword:00000002
I also tried to use CharToOem/Oem2Char Win API functions, it doesn't help.
Any ideas?
Okay I have solved this by changing following registry values:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Xbase]
"DataCodePage"="ANSI"
"BDE"=dword:00000002
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage]
"1252"="1251.nls"
Last setting has solved the issue.

Microsoft Visual Basic Error

I have a table in an access database that keeps giving my a run-time error '3044' 'Y:\InfoSystem\CommData.mdb is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. I don't understand why I am getting this error because the information should be coming from my C: drive and not the Y: I haven't changed anything to make it occur. Is there a way to change it to the C: drive? I believe it is a linked table.
you have somewhere in your code a connection string that tells vb when to find the db. make sure that the path is right. try to search the whole project for "CommData.mdb"
it should be something like that:
Connection1.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\CommData.mdb" & ";Persist security Info=False"
another approach is to try to set the path manually in your code

See actual code of function in DB2 for IBM i

Hello guy I create a function in DB2 UDB for AS/400 version 07.01.0000 V7R1m0
I use a windows with dbvisualizer to connect the server.
My function is...
CREATE FUNCTION JVAOBJ.BNOWPAPOL(POL VARCHAR(10)) RETURNS DECIMAL(7,7) LANGUAGE SQL NOT
DETERMINISTIC READS SQL DATA
RETURN
(
SELECT
CASE
WHEN NUM IN (1,2)
THEN 0.3
ELSE 0.19698
END AS VALOR
FROM
LMDDTA.VERT240
WHERE
POLLIFE = POL )
It return 0.3 or 0.19698 depending of POL param
To do it I delete DROP FUNCTION JVAOBJ.BNOWPAPOL and run CREATE until work well.
My problem is I can not see the actual code of the function in dbvisualizer I cant see the function created
How I can see the actual code?
Note:
The server administrator has access to the console as400 (yes, that black screen with green letters or orange letters, which I have not much knowledge)
maybe, I can see it from here.
Note 2:
I use jt400 driver to connect.
Try IBM i Navigator for web. If it is configured on your machine, you can reach it through this URL: https://your.ibm.i:2005/ibm/console/login.do?action=secure
If it is not configured, then perhaps you can ask the admin to install the Windows client. It is part of Client Access for Windows and is called IBM i Navigator for Windows.
In either case, use the navigation tree to go to Databases > machine > Schemas > JVAOBJ > Functions. Right click your function > Definition and then choose Routine Body
EDIT Add SYSROUTINE
Another way to see the routine body is via the DB2 catalog table SYSROUTINE. select specific_schema, specific_name, routine_definition from sysroutine
I know IBM i Navigator its a great tool, but you need some amount of knowledge to master it.
The easiest way is to query the SQL system tables using dbvisualizer
SELECT * FROM qsys2/sysfuncs
WHERE (SPECIFIC_SCHEMA, SPECIFIC_NAME) = ('JVAOBJ', 'BNOWPAPOL')