How to save password for database - mailmerge macro writer libre office

Hello,
when I run a mailmerge writer macro I have to set the password for the database, otherwise i get an error. When I open a writer template that also access the database I get a dialog to enter the database password. Then the macro works.
But is there a way to store the password directly in the mailmerge macro or in the settings of libreoffice, so that i do not have to enter it every time again?

Macro:
DIM oMailMerge AS OBJECT
DIM aProps() as object

oMailMerge = createunoservice(“com.sun.star.text.MailMerge”)

oMailMerge.DataSourceName = “postgres”

Maybe something like - oMailMerge.DataSource.Password = “password”? This does not work.

Error:
Type: com.sun.star.sdbc.SQLException
Message: Couldn’t establish database connection to ‘sdbc:postgresql:postgresql://localhost:5432/postgres’
fe_sendauth: no password supplied

Thanks for your reply!

Hello,

It is not recommended to bypass database security. With your request, no matter how it is achieved, it is nothing more than opening the door to access your database.

With that said, you can add the user name and password onto the Base .odb connection string (or alternatively to the Base content.xml file).

See the answers and comments in these posts:

How to store password for MySQL

Standalone Form with non-embedded database

Have just tested adding to connection string:

?user=your_login&password=your_password

with PostgreSQL connection (did SDBC, JDBC and ODBC). Then creating labels from a writer document. There was no login required. Also note, there is no login required in the Base file either or anywhere else the connection is made to this Base file.

As with all questions, if this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.

FYI - Spent a number of hours trying to get Mail Merge to accept user, PW info. Got to a point of a successful result set but when it came time to send the email LO crashes consistently.

thank you.

It is now possible to connect without exposing the password etc. to the user.

postgresql://$host:$port/$database?user=your_login&password=your_password