VBA Connect to MSSQL from Ubuntu

I have a small VBA macro that uploads a selected row to a MS-SQL database. The sheet works fine on Windows. I have now switched my PC over to Ubuntu and am trying to update the macro so that I can do these uploads there too.

The relevant part is the following.

      Set Cobj = CreateObject("ADODB.Connection")
      Cobj.Open "DSN=lXTC;Uid=Username;Pwd=secretPassword"

      For r = 0 To UBound(vSel, 1)
          vSQLi = "IF EXISTS (SELECT Date FROM ...."
          Cobj.Execute vSQLi
      Next

      Cobj.Close
      Set Cobj = Nothing

Now it throws an error saying it can’t load the module. I have installed the MS ODBC drivers on the Ubuntu machine and can connect to the database from the command line with isql -v lXTC username password

What do I have to change to connect to the database? Bonus solution would be, if both Windows and Ubuntu would work at the same time, cos I still have a Windows PC and then I could run it from both.

  • Create an ODBC connection. There is a program odbcinst.
  • Connect a Base document like this:
    menu:File>New>Database…
    Connect to existing, type ODBC, specify the name and create the query.

Thanks for the suggestion. Well, I tried to create a new Database connection, but when I try to select a data source in step 2, I just have an empty list.

When I run odbcinst -q -d I do see the DSN name, but not in Libreoffice.

And even if I could create the database connection, it still would show the error about the module not being able to open, no?

As you use Ubuntu: Is your LibreOffice installed as Snap?
We often see problems with integration of snap-installs, from browsers not showing local LibreOffice-help to not accessible parts of the file-system. I’d assume a LibreOffice snap is simply not allowed to access any ODBC-resource.
(Most distrobutions remove even Base from LibreOffice…)

Yes, I believe so. So you suggest I should try to install it again without snap? I will try to figure out how I do that.

sudo apt remove snapd

Ok, so I uninstalled Libreoffice from the app center and installed it directly.

However, when I now try to create the database connection, the DSN list is still empty and the DSN defined don’t show up.