why can't I connect to the database using wildfly data? - database

This is the first time I try to deploy my application using wildfly to a remote server, it seems that I succeeded, but now I cannot connect the created database. wildfly says that
Connection URL = jdbc:postgresql:/var/run/postgresql:5432,
I use this string to connect
<property name="connection.url">jdbc:postgresql:/var/run/postgresql:5432?currentSchema=myshema&user=user&password=pass</property>
For this I get
Connection error: : org.postgresql.util.PSQLException: FATAL: database "/var/run/postgresql:5432" does not exist
in logs. What am I doing wrong?

Related

How to connect a .NET API to a SQL Server database both in the same Kubernetes cluster?

I have a SQL Server running in a pod and an API running in another pod in the same cluster deployed with helm.
I'm able to connect to the database with a port forward and I created a user using Microsoft SQL Server Management Studio.
I point out that it's for a development environment and all is ok in production (production databases are outside the cluster).
When my API is deployed, this error is thrown in his pod :
An error occurred seeding the DB.
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
And
An error occurred using the connection to database 'dbdev' on server '127.0.0.1,1433'.
I wonder which connection strings to put in order to connect to the database because with that connections strings, it doesn't work :
"Server=tcp:127.0.0.1,1433;Initial Catalog=dbdev;Persist Security Info=False;User ID=xxxxxx;Password=xxxpasswordxxx;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=True;Connection Timeout=30;"
If it's a problem of connection strings, isn't localhost point inside my cluster ? or am I out of step.
Ok i found out my problem, i dont have to put IP address in my connection strings but the name of the service in the cluster.
"Server=service-name-in-cluster,1433;Initial Catalog=dbdev;Persist Security Info=False;User ID=xxxxxx;Password=xxxpassxxxx;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=True;Connection Timeout=30;"
This error message indicates that the .NET API is unable to establish a connection to the SQL Server database. There could be a few reasons why this is happening:
Incorrect server name or port: Make sure that the database host and
port specified in the API's configuration are correct. You can verify
this by checking the name and port used in the SQL Server Deployment
and Service.
Network connectivity: Ensure that the .NET API and SQL Server are in
the same network and can communicate with each other. You can use
kubectl exec to run a ping command from the API pod to the SQL Server
pod to test the connectivity.
Firewall rules: Make sure that the SQL Server port is open and
accessible from the .NET API. If you're using a firewall, you may
need to add a rule to allow traffic on the SQL Server port.
Incorrect credentials: Make sure that the credentials specified in
the API's configuration are correct and match the credentials used by
the SQL Server.
SQL Server instance not running: Check that the SQL Server instance
is running and accessible. You can do this by checking the status of
the SQL Server pod in the cluster and making sure that the SQL Server
service is running.
If the issue persists, you may need to inspect the logs of the API pod and the SQL Server pod to gather more information about the problem.

What can cause to a failed database connection for a spring boot application other than incorrect datasource settings?

I have configured my spring boot application to run from a remote sql server database deployed to one of our environments with ip and port configuration below. And it works with no issue.
datasource.common.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
datasource.common.platform=mssql
datasource.common.username=${dbUsurname}
datasource.common.password=${dbPassword}
datasource.common.url=jdbc:sqlserver://10.223.124.566:31567;databaseName=acc
But when I replace my connection to another database instance that is deployed for another environment , even if I supply correct username , password and ip combination I get error.
datasource.common.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
datasource.common.platform=mssql
datasource.common.username=${dbUsurname}
datasource.common.password=${dbPassword}
datasource.common.url=jdbc:sqlserver://10.223.124.211:31567;databaseName=int
I get the following trace.
Cannot open database "int" requested by the login. The login failed.
ClientConnectionId:0dd4761b-8969-4848-96f8-c7ca41c48bf
I can connect to database with which I got error in spring application from mssql management studio with the given configuration and had no issue connecting it. Is there any setting for a database instance that prevents applications from connecting it other than username and password ?

.Net Core App in Openshift linux Pod connecting to SQL Server

I have a .net Core Rest Service deployed in OpenShift which connects to an External SQL Server. I have added the Host Name in the configuration for my namespace. I also have Kerberos setup in a side car
I still have connection errors
my connection string is as follows
"ConnectionStrings": {
"SqlDbContext": "Server=ServerXYZ\\InstanceXYZ,55001;Database=myAppDB;Integrated Security=True;
}
The error I get is
“SqlException: A network-related or instance-specific error occurred
while establishing a connection to SQL Server. The server was not
found or was not accessible. Verify that the instance name is correct
and that SQL Server is configured to allow remote connections
”
When I run the api from my local windows PC iw works fine, but I am not sure if I need to adapt the connection string for the OpenShift Linux pod
The solution was to use the full domain name of the SQL Server myserver.mydomain.com

Dotnet core application cannot connect to SQL server using IIS, only when using IIS Express or Kestrel

I have a .NET Core web application that fetches some data from a SQL Server. I connect to the SQL Server over the internet.
When I run the application with IIS Express or Kestrel, I can connect to the database server and retrieve data. I can also successfully connect to the database server using SQL Server Management Studio.
Here is the connection string I'm using:
"ConnectionStrings": {
"DefaultConnection": "Server=my-sql-server.someurl.com; Initial Catalog=my-sql-database; User ID=my-user-id; Password=my-password;"
}
But when I try to run the same website, on the same machine, in IIS, I get the following error message:
SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No such host is known.)
I'm suspecting this has something to do with the dotnet core/IIS combination, and not a firewall/network/authentication issue, but I might be wrong.
The issue was simply that I was looking at the wrong connection string.
I have appsettings.json containing one connection string and appsettings.Production.json containing another.
When running the application with IIS Express or Kestrel, the first one is used, but when I publish the app and then run it under IIS, the environment is set to Production, and the production settings are used instead.
The problem was that the production connection string pointed to a database server that didn't exist anymore.
I solved this issue by adding LocalSystem to Identity in Web site Application pool.
Steps:
Select website application Pool
Right click and click Advanced Setting
Click on Identity, and change it to LocalSystem
You need to enable TCP/IP protocol on sql server. Please use following link:
Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?

Hostinger, what is the url of database

I am trying to connect to my hostinger database but it does not work:
<property name = "javax.persistence.jdbc.url" value = "jdbc:mysql://mysql.hostinger.fr/myDBName"/>
I have the following error:
java.net.UnknownHostException: mysql.hostinger.fr: nodename nor servname provided, or not known
Hostinger does not allow you to connect remotely on your database with a basic free account. You need to deploy your application to test the connection.

Resources