Jhipster and Postgres connection - database

I'm trying to run the project in Jhipster based on this tutorial by the creator himself :https://www.youtube.com/watch?v=d1MEM8PdAzQ but it can't connect to Postgres
See errors below:
Caused by: org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided.
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:473)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:203)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:146)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:35)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:47)
at org.postgresql.jdbc42.AbstractJdbc42Connection.<init>(AbstractJdbc42Connection.java:21)
at org.postgresql.jdbc42.Jdbc42Connection.<init>(Jdbc42Connection.java:28)
at org.postgresql.Driver.makeConnection(Driver.java:415)
at org.postgresql.Driver.connect(Driver.java:282)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:101)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:316)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:518)
How do I connect Jhipster with postgreSQL? I am a newbie on jhipster

JHipster creates 3 configuration files: -
application.yml - main Spring Boot configuration file.
application-dev.yml
application-prod.yml
The application.yml file contains common properties, the other 2 hold specific properties to development and production environments.
If you look at application-dev.yml you'll see something like the following: -
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/myapp
username: myapp
password:
However, you still have to create your PostgreSQL database - the easiest way is via the pgAdmin tool but you can also create it via command line tools - a quick google will help you there!

If you don't want to work with docker compose file Version 3 in docker swarm mode, where it is best practice to use docker secrets, then you can create an .application.env-file and link it in your docker-compose.yml (Version 2) with 'env_file:'
$ cat .application.env
SPRING_PROFILES_ACTIVE=prod,swagger
SPRING_DATASOURCE_URL=jdbc:postgresql://postgresql:5432/database_name
SPRING_DATASOURCE_USER=database_user
SPRING_DATASOURCE_PASSWORD=database_password
JHIPSTER_SLEEP=10
[...]
At least I use it this way to keep the credentials away from my jhipster-projects, which are on Github, where I also want to put the *.yml-files.

Related

Sanity Deployment in Azure Pipeline

I'm trying to deploy my sanity react app, here's the repo:
https://github.com/sebastian-meckovski/sanity-admin-area
here's my yml file:
trigger:
- main
- feature/*
pool:
vmImage: 'ubuntu-latest'
variables:
SANITY_AUTH_TOKEN: $(SanityDeployAPIToken)
SANITY_STUDIO_PROJECT_BASEPATH: /studio
steps:
- task: NodeTool#0
inputs:
versionSpec: '14.x'
- task: CmdLine#2
inputs:
script: |
cd src/Studio
npm install -g #sanity/cli
npm install
sanity deploy
been using this article for help: https://blog.novacare.no/deploy-sanity-studio-with-azure-devops/
I'm getting this error in cmdline in azure:
Your project has not been assigned a studio hostname.
To deploy your Sanity Studio to our hosted Sanity.Studio service,
you will need one. Please enter the part you want to use.
any ideas?
Sanity Deployment in Azure Pipeline
That is because you would be asked to choose a unique hostname for your Studio when you first deploy sanity.
This is a pop-up verification window that needs to interact with our developers.
But the hosted agent is in the service mode instead of Interactive. Please check the docuement Azure Pipelines agents for some more details.
In this case, the verification window will not pop-up for the hosted agent. That is the reason why you get the error the project has not been assigned a studio hostname.
To resolve this issue, you need to create your private agent and set it as Interactive mode.
Self-hosted Linux agents
Or you could just deploy it from your local with command line, so that you could assign a studio hostname.
Of course, a more complete solution would be to have Sanity pre-specify the hostname somewhere (a json-like file) and then read it when deploying Sanity without specifying it during the process. But I'm not a Sanity expert and it's not clear if there is such a way.

Configure Postgre DB in docker project

I'm very new to docker and docker-compose things. I have tried to use Kiwi TCMS open source project which supposed to use with Docker.
My question is can I run the projects on docker on the same server, I'm supposed to configure my development and production sites on the same server (CentOS)?
I'm following the below link to install docker and configure the kiwitcms application for the first time, I read the basics about the docker and how its working and all.
https://kiwitcms.readthedocs.io/en/latest/installing_docker.html#
I want to use PostgreSQL as my Database, but the existing latest docker image has MariaDB. So after I pulled latest version of kiwitcms from docker hub using the following command,
docker pull kiwitcms/kiwi
Should I change to "docker-compose.yml" file db image value, and save it to a local new directory,
https://raw.githubusercontent.com/kiwitcms/Kiwi/master/docker-compose.yml
[![enter image description here][1]][1]
Also there can we edit use our own DB name, user name passwords right?
then execute the following command.
docker-compose up -d
I'm very new to this model and read most of the articles related to docker, but this leads me few of these doubts, hence asking for these clarifications.
Thanks,
Karthik.
The web app and the DB server are 2 different images (aka 2 different servers). For example how we use Postgres in testing see:
https://github.com/kiwitcms/Kiwi/blob/master/docker-compose.postgres

Connect to MSSQL from Spring boot application using windows authentication

I am currently using the below properties to connect to a remotely Mssql server from Java spring boot application:
spring.datasource.url=jdbc:sqlserver://ip\\domain;databaseName=name
spring.datasource.username=abc
spring.datasource.password=def
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
The application runs from both windows and unix servers. I need now to start using the windows authentication instead of the db credentials. This is already configured and supported from MSSQL side. From Java spring boot this is not working. I tried to add to the url: integratedSecurity=true it said it cannot find a dll. I added sqljdbc_auth.dll to java jre bin folder and it didnt work.
I'm working on MS SQL Server 2016, Hibernate 5.3.7.Final and Spring bot 2.2.0. For me, adding this line to properties worked: (without jtds!)
spring.datasource.url=jdbc:servername;databasename=your_db_name;integratedSecurity=true
You may also need these properties:
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
And if you encounter a problem with "no sqljdbc_auth in java.library.path".
You may refer to this answer no sqljdbc_auth.
Try use jtds driver, and in apllication properties use:
app.datasource.youraplication.jdbcUrl=jdbc:jtds:sqlserver://yourBdHost/yourSchemaBd;domain=yourDomain
Download the drivers from:
https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-2017
Add the jar to your project Right Click on project - > Build Path -> Configure Build Path - > Libraries -> Add External JARs
Add "integratedSecurity=true" to your connection string and remove username and password

Connecting Phoenix app to MS SQL Azure database

I am trying to connect a phoenix application to MS SQL. After looking around online I came across a couple of adapters called mssql_ecto & mssqlex.
I have added them to the project following the instructions in the readme, installed odbc and checked that the db is online but I am now getting the following error..
[error] Mssqlex.Protocol (#PID<0.13069.0>) failed to connect: ** (Mssqlex.Error) odbc_not_started
My app is configured as below..
config :my_app, MyApp.Repo,
adapter: MssqlEcto,
username: "<my_username>",
password: "<my_password>",
database: "test",
hostname: "<my_server>.database.windows.net",
pool_size: 10
My environment is as follows..
MacOS Sierra 10.12.5
Elixir version: 1.4.4
There is an issue in the mssql_ecto repo already, and I have tried the suggestions from there, but it still has not worked.
If anyone has managed to connect their phoenix/elixir application to MSSQL on macOS and could provide some instructions it would be greatly appreciated (even if it was done in a completely different way to my approach 😉 ).
Side note: Tried it in node with the same db and was able to connect to and query the db.
I've been working through the same issue this week, connecting to an Azure SQL Database, and this is what I've got working.
You are seeing the first of 2 main problems I ran into:
Erlang installed without ODBC
Mssqlex adapter is missing required configuration options
#1: Erlang installed without ODBC
If you've installed Elixir and Erlang using brew, or something like it, you are getting an installation of Erlang that does not include erlang-odbc. In order to remedy this, you will need to install Erlang from source.
I recommend that you install both Erlang and Elixir from source using the method documented here:
http://www.lambdacat.com/how-to-install-elixir-on-mac/
Just make sure that you remove the Kerl option, --without-odbc, before you build Erlang.
Now that you have Erlang installed correctly, the odbc_not_started error should go away... to be replaced by connection errors to the database.
#2: Mssqlex adapter is missing required configuration options
As of this moment, the mssqlex adapter does not support the following configuration options that Azure is looking for:
Encrypt
TrustServerCertificate
Connection Timeout
To get around this issue, I forked the mssqlex library and added those options in a branch. I am not committing to maintaining this so feel free to fork it yourself.
In order to use the modified mssqlex, replace the mix dependency with the github location and branch name:
{:mssqlex, git: "https://github.com/tvanhouten/mssqlex.git", branch: "azure-settings", override: true}
The override: true is important because mssql_ecto has a dependency on the mssqlex version in hex.
Now you can update your configuration:
config :my_app, MyApp.Repo,
adapter: MssqlEcto,
username: "<my_username>",
password: "<my_password>",
database: "test",
hostname: "<my_server>.database.windows.net",
pool_size: 10,
encrypt: "yes",
trust_server_certificate: "no",
connection_timeout: "30
Other "Gotchas" to Look Out For
Azure requires TCP connection:
In order to connect to an Azure SQL Database, you will need to make sure that the hostname: option starts with tcp:. So, all together, it will look like
hostname: "tcp:.database.windows.net"
Mssql_ecto does not support Ecto 2.2+:
If you're getting errors related to Ecto or Ecto.SubQuery, you probably need to make sure that you are using a version of Ecto that is supported by mssql_ecto. At this point in time, that means Ecto 2.1.x. Again, this requires a slight change to your mix dependencies:
{:ecto, ">= 2.1.0 and < 2.2.0"}
Dependency cache and lock issues:
If everything seems to be in order according to the above but it just doesn't seem like the new dependencies are being updated and compiled as expected, do the following:
Run mix deps.clean --all
Delete the mix.lock file from your root project directory
Run mix deps.get
Run mix deps.compile
That should do it!

Configuring a Postgresql connection with Play 2 and Slick-Play

I'm learning how to build an application using Scala and the Play 2 Framemork. I`ve created a new project using the activator tool, based on "play-scala-intro" current template.
The template have a sample app using the Play-Slick 1.0 for managing dependencies and is configured with a H2 DB, that worked without problems.
When I tried to change to a Postgres DB, I'm running in trouble. I get an error 500, telling me:
"Cannot connect to database [default]".
In the stack trace, the exception is:
"Configured Slick driver org.postgresql.Driver is not an instance of
requested profile slick.profile.BasicProfile"
So... What I already did:
I added to my build.sbt file the dependency:
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41"
In my configuration file (application.conf), the DB connection is configured as:
slick.dbs.default.driver=org.postgresql.Driver
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/hello_play"
slick.dbs.default.db.user="postgres" slick.dbs.default.db.password=""
PS: I've tried with slick.dbs.default.driver="org.postgresql.Driver" too...
PS2: My db password is empty. I'm connecting with PgAdmin without problems
slick.dbs.default.driver must be a slick driver, not a JDBC driver. Your db config should look something like this:
slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/hello_play"
slick.dbs.default.db.user="postgres"
slick.dbs.default.db.password=""

Resources