Impossible to connect to PostgreSQL DB via VBA - excel

I have a problem trying to connect to my local PGSQL db via VBA. My code looks like this :
Set conn = CreateObject("ADODB.Connection")
strCnx = "Driver={PostgreSQL Unicode}; Server=127.0.0.1; Database=postgres;
UID=postgres;Pwd=***;port=5432"
conn.Open strCnx
The error I get is
[Microsoft][ODBC Driver Controler]DATA SOURCE NAME NOT FOUND AND NO
DEFAULT DRIVER SPECIFIED
I have tried a few things I found on stackoverflow, mainly installed the odbc drivers for postgresqlx64, and tried to connect to the database using directly ODBC, which told me success when I tried to connect (picture below).
Testing connection to PGSQL DB directly via ODBC
But despite everything I tried, the error is the same when I try to execute my VBA code, and I'm out of ideas, so if there are any way you could help me, I would be most thankful :)
Thanks
Frost

Make sure you install an ODBC driver with the same bitness as the application hosting your VBA. So 32-bits Excel means you need the 32-bits (x86) ODBC driver.
If you install the proper ODBC driver, this error should go away.

Related

Does VBA have a psycopg2 style way to connect to PostgreSQL?

I have been running queries in SQL in Python using psycopg2. This is very simple and I just do the following:
conn2 = psycopg2.connect('postgresql://YourUserName:YourPassword#YourHost:5432/YourDatabase')
query = "xxx"
query_output = pd.read_sql_query(query, conn2).drop_duplicates(keep='first')
Is it possible to something similarly as easy in VBA? I am hoping to create an easy-to-use excel add-in so want to avoid asking the user to have to set up 32-bit drivers in ODBC Driver Manager.
I am trying to develop a setup here:
Dim objDb_con
Dim strSomeValue As String
Set objDb_con = CreateObject("ADODB.Connection")
Set Rsdatatype = CreateObject("ADODB.RecordSet")
glbConnString = "Driver={PostgreSQL UNICODE};Database=XX;port=XX;server=XX;UID=XX;Pwd=XX;"
objDb_con.Open glbConnString
But I get the error:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Looking around it appears this is to do with ODBC driver managers and even though I tried to set-up the default as 32-bit I still get this error.
Is there a psycopg2-style alternative for VBA that is simple and doesn't require set-up for the user?
I always pull connection strings from this website:
https://www.connectionstrings.com/progress/
They clearly show that there is no built-in .NET libraries or OLE DB providers for PostGress. Thus, you cannot get around installing the driver. You could package an installer to automate this process.
If you have the ODBC drivers installed you would use a connection string like this:
Standard
Include only the parameters you want to override from the system DSN settings
DSN=myDSN;HOST=myServerAddress;DB=myDataBase;UID=myUsername;PWD=myPassword;PORT=2055;
Alternative using long names
Include only the parameters you want to override from the system DSN settings
DataSourceName=myDSN;HostName=myServerAddress;Database=myDataBase;LogonID=myUsername;Password=myPassword;PortNumber=2055;

Connect Mac Excel 2016 to local MAMP SQL database

As per the title I'm trying to connect to local MAMP database. This should be possible as Excel Mac 2016 includes Simba ODBC driver. However when I try and set up a connection via the dialog box shown, I always get an error shown below.
I've use the standard MAMP settings for the sql server as shown in first image.
Any help would be much appreciated as is hard to make this work.
Thanks
MAMP settings
Excel Dialog box
Error message
I've finally got this connecting.
Info which solved the answer found at
https://github.com/openlink/iODBC/issues/29
Basically excel 365 is sandboxed and so even if you create a DSN that tests ok in iODBC, it just continues to crash excel if you try to connect to it. Also I'm guessing sandboxing explains why excel is not able to see User DSNs created with iODBC, and can only see system ones.
So for others trying to connect Excel to MySQL, I needed to download iODBC to set up DSNs, and then download the iODBC connector for the ODBC drivers.
https://dev.mysql.com/downloads/connector/odbc/
I then moved the driver libraries from /usr/local/mysql..... to /Library/ODBC/mysql...
I created a system DSN (as excel seems only to see the system ones) with keys
server 127.0.0.1
port 3306
username root
password *
[These details came from the MAMP page]
And then I was able to connect!

Microsoft ODBC Driver for Oracle gives ORA-01019 error, can't seem to find the oracle driver

I'm getting an error trying to connect to an Oracle DB, and I'm pretty sure I have my variables out of whack.
The error I'm getting is
Microsoft ODBC Driver for Oracle gives ORA-01019 error, can't seem to find the oracle driver
My current Environment and System variables are as such:
System Variables:
ORACLE_HOME: C:\app\MyUser\product\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2
I also have a Path variable reference: Same path C:\app\MyUser\product\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2
I do not have a reference to the Oracle client in my User Variables, though.

Query excel based database from SQLDeveloper

I am on a Windows 7 machine and have configured a ODBC connection by name of 'MyExcelDb' to an excel file. I am able to programatically connect to 'MyExcelDb' using type-1 jdbc driver and everything is working fine.
I now want to use Oracle SQLDveloper to query the DSN 'MyExcelDb' but I am not able to make this connection as I do not find any option for ODBC Connection. I have tried using the 'advanced' option in Oracle section and tried putting custom jdbc URL as 'jdbc:odbc:excelDB' bugt to no avail.
I have tried adding entries in SQLDeveloper for third party drivers like:
- sourceforge.net/projects/xlsql/
- code.google.com/p/sqlsheet/
- hxtt.com/excel.html
Despite this but no new connection option would appear and I am still struggling to make connection between the two.
I have searched around and found that I could install Oracle and add a TNS for the excel and that way I may be able to connect using the Oracle TNS in SQLDeveloper. Installing Oracle database but would be like killing a mosquito using a canon.
I wonder if there is a simple solution to my problem.
Have you tried following Oracle's guidelines for connecting to Excel files? Did you set up a system DSN as described in step three of the Oracle guide. Importing files into the database is routine and simple but using SQL Developer in the manner you describe, without the client installed. Here is an example of reading an Excel file via PL/SQL.
My question is why use SQL Developer to manipulate a datastore in Excel when Excel is designed to manipulate the data?

access Lotus notes database using ODBC and C#

Please provide some sample code how to access Lotus notes database using ODBC and C#.
Now I am able to accessing database suing NotesSession() class.but I want how to do via ODBC
Thanks and Regards
Naresh Mesineni
Thanks for your replay.Still I am facing some problem.I downloaded the NotesSQL 8.5 and installed.
I am trying to get the Notes data using ODBC still It is throwing some error.Here I am attaching connection string.
string sConnString = "Driver={Lotus NotesSQL 8.5 (32-bit) ODBC DRIVER (*.nsf)};" +
"Server=serverXXXX;" +
"database="DBName;"
"Uid=userxxx;" +
"Pwd=pwdxxx";
OdbcConnection odbccon = new OdbcConnection(sConnString);
odbccon.Open();
while opening connection it is throwing error
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
Please provide some solution.it is help full if any one provide sample code with getting data from Notes.
Thanks and Regards
Naresh Mesienni
You'll need to use the NotesSQL driver, and the help file is here.
You can setup a DSN, or use the connection strings found on connectionstrings.com
Driver={Lotus NotesSQL 8.51 (32-bit) ODBC DRIVER (*.nsf)};Server=myServerAddress; Database=dbPath\myDb.nsf;Uid=myUsername;Pwd=myPassword;
How about LEI? (Lotus Enterprise Integrator)
I think is free with Domino and it lets you create ODBC connections and schedules jobs, etc.
You should look into it.

Resources