How can I call a postgresql db stored in DigitalOcean from ASP.NET Core web api? - postgresql

I'm tying to use the connection string provided by DigitalOcean directly on the appsettings.json file, but shows error
ArgumentException: Keyword not supported: postgresql://XXXXX_user:xxxxxxxxxxxxx#db-trackbus-nyc3-xxxx-do-user-xxxxx-0.b.db.ondigitalocean.com:xxxxx/trackbus?sslmode (Parameter 'keyword')
Npgsql.NpgsqlConnectionStringBuilder.GetProperty(string keyword)
This is the exact connection string provided by DigitalOcean:
postgresql://xxxx_user:xxxxx#db-trackbus-nyc3-xxxx-do-user-xxxxx-0.b.db.ondigitalocean.com:xxxxx/TrackBus?sslmode=require
I'm using Npgsql nuget package, when the db was local was working fine using th regular connection string
"Server=xxx.0.0.x;Port=xxxx;Database=TrackBus;User Id=postgres;Password=xxxx;"
I've also tried this (private and public):
"Server=private-db-trackbus-nyc3-xxxxx-do-user-xxxxx-0.b.db.ondigitalocean.com;Port=xxxxx;Database=TrackBus;User Id=xxxxx_user;Password=xxxxxxxxxx;Integrated Security=true;"
Error:
An unhandled exception occurred while processing the request.
PostgresException: 28000: no pg_hba.conf entry for host "xxx.xxx.xxx.xxx", user "xxxx", database "TrackBus", SSL off
I searched this last 28000 exception but couldn't apply any solution found.

The connection string provided by DigitalOcean is for CLI:
postgresql://xxxx_user:xxxxx#db-trackbus-nyc3-xxxx-do-user-xxxxx-0.b.db.ondigitalocean.com:xxxxx/TrackBus?sslmode=require
You have to convert it to the format that appsettings.json uses and it will be like this:
"Server=db-trackbus-nyc3-xxxx-do-user-xxxxx-0.b.db.ondigitalocean.com;Port=xxxxx;Database=TrackBus;User Id=xxxxxxxx;Password=xxxxxxxxx;sslmode=Require;Trust Server Certificate=true;"
The sslmode=Require;Trust Server Certificate=true; is super important because the managed database in DigitalOcean has it that that one.
Also remember that all postgresql database by default are blocking remote connection, you have to add the permission on the pg_hba.conf file from the Postgresql installation folder.

Related

Has someone connected a PostgreSQL DB hosted in GCloud with Microsoft SSMS?

I have a question, I do not know how to solve it yet. Perhaps someone here has faced a similar issue.
We have a PostgreSQL DB hosted on Gcloud. We usually use a cloud proxy to connect with the database. It usually works very well!! In a nutshell the proxy connect a port from local host, to the actual DB host.
However this time, we want to connect it with Microsoft SSMS. We have not find an option where we can connect Microsoft SSMS with a DB running locally (this means connecting to a database on a port in local host).
The ultimate goal is to connect the database with Power BI. So if someone know how to connect a PostgreSQL DB hosted in GCloud to power BI that would also be very helpful!!
We have followed this tutorial:
https://www.anibalum.com.ar/2020/06/creating-linked-server-with-postgres.html
However we get the following error:
The linked server has been created but failed a connection test. Do you want to keep the linked server?
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "PAPERFLOWDB".
OLE DB provider "MSDASQL" for linked server "PAPERFLOWDB" returned message "[Microsoft][ODBC Driver Manager] Invalid connection string attribute".
OLE DB provider "MSDASQL" for linked server "PAPERFLOWDB" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified". (Microsoft SQL Server, Error: 7303)
We are using Microsoft SSMS v18.9.1

Not able to make postgres database call on heroku using Play Framework Application

I am build REST api using play framework 2.8 , I am able to start the application and call some service. Facing issue when trying to connecting with postgres database. Logs are below -
Error opening connection for database: {}org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "3.87.112.32", user "abc", database "xyz", SSL off
Tried looking solution for this and foudn have to add sslmode=require in query param while connection to database.
When log the url sslmode is already mentioned.
jdbc:postgresql://abc.amazonaws.com:5432/xyz?password=1234&sslmode=require&user=xyz
I am reading this property from heroku env variable JDBC_DATABASE_URL for obtaining database connection.
This issue can be fixed by adding addition query parameters apart from sslmode=require which are ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory after adding this the new URL become jdbc:postgresql://abc.amazonaws.com:5432/xyz?password=1234&sslmode=require&user=xyzssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

How to update Pentaho Spoon JDBC drivers

I'm trying to connect to a postgresql 13 DB hosted on my computer using spoon.
I get the following error when trying to connect
Error connecting to database [DW] :org.pentaho.di.core.exception.KettleDatabaseException:
Error occurred while trying to connect to the database
Error connecting to database: (using class org.postgresql.Driver)
The authentication type 10 is not supported. Check that you have configured the pg_hba.conf file to include the client's IP address or subnet, and that it is using an authentication scheme supported by the driver.
org.pentaho.di.core.exception.KettleDatabaseException:
Error occurred while trying to connect to the database
Error connecting to database: (using class org.postgresql.Driver)
The authentication type 10 is not supported. Check that you have configured the pg_hba.conf file to include the client's IP address or subnet, and that it is using an authentication scheme supported by the driver.
I did some digging and that's due to an outdated JDBC driver. Can anyone help me update the driver? I have located the driver directory but the guide on the website https://help.pentaho.com/Documentation/5.4/0D0/160/030
is just crap, they require you to have a distribute-files.bat file? Which I couldn't find anywhere.
You do not have to follow all the steps. Just pasting the JAR file in the directory is enough.

Getting org.postgresql.util.PSQLException: FATAL: database "null" does not exist in SpringCloudDataFlow

I'm getting "org.postgresql.util.PSQLException: FATAL: database “null” does not exist" in connecting PostgreSQL to my SpringCloudDataFlow Server App in PCF environment.
I have successfully performed following steps.
Deployed SCDF(Spring-Cloud-Dataflow) server in PCF (1.7.3 version)
Created PostgreSQL service instance with 'Standalone' plan. Note: I don't have any other database service available in PCF marketplace.
Connect to that instance (using host (IP) and autogenerated credentials) by a third party software and create database using script 'CREATE DATABASE scdf'
Bind 'PostgreSQL service instance' with 'SCDF server app'.
Set environment variables
spring_datasource_driver_class_name = org.postgresql.Driver
spring_datasource_username [PostgreSQL_Instance_Autogenerated_Username]
spring_datasource_password [PostgreSQL_Instance_Autogenerated_Password]
spring_datasource_url "jdbc:postgresql://10.254.48.231:5432/scdf"
After setting environment variables, when I restart SCDF server app, it gives exception and crash the app
org.postgresql.util.PSQLException: FATAL: database “null” does not exist
Can anyone help please.
A good first step is to make sure the PostgreSQL service-instance is functional on PCF.
Perhaps you could connect to the host/user/pass from outside of PCF via a DB client tool or from other applications. If this is successful standalone, then there's something wrong in supplying the credentials to the SCDF-server.
It is unclear how you're supplying database properties to SCDF. You may have to wrap those "datasource" properties as a well-defined JSON, and provided as the value for SPRING_APPLICATION_JSON property attached to the SCDF-server. If you continue to see issues, please update the description with manifest.yml and other information about the environment.

ASP.NET core connection string - use AWS RDS

I would like to switch from using a local db in my web app, to aws relation databases (RDS).
I have connected to the aws RDS via mysql workbench.
In order to make this switch, all I have changed is the connection string. But it doesn't work. (it hangs for 30 seconds then throws HTTP Error 502.3 - Bad Gateway).
the local db: =Server=localhost;database=ef3;uid=root;pwd=123456;
But when I change it to Server=test2.xxx.ap-southeast-2.rds.amazonaws.com;database=test2;uid=xx;pwd=xx;port=3306;, I get the following output from the console.
https://pastebin.com/raw/qA0py6t0
The last line says: "Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware","{OriginalFormat}":"An unhandled exception has occurred while executing the request"}}}
How do I fix the connection string, to connect to the AWS RDS?
Thanks guys
The connection seems fine, seems like that database doesn't contain the expected data.
From the trace:
MySql.Data.MySqlClient.MySqlException: Table 'test2.Events' doesn't exist