AWS Lambda - RDS Proxy creating a connection takes more time - java

As we can't use native DBCP or any kind of java connection pool in AWS Lambda I have been using RDS proxy to connect MYSQL DB, But Still it takes 5 to 6 secs to make connection but I need the response from the lambda in <1 secs it there any way of keeping the connection warm. I'm using DriverManager.getConnection to get connection from RDS proxy
I have tired to connect proxy using
java.sql.DriverManager
Connection con = DriverManager.getConnection(("DB_Primary_IP"),("DB_Username"),("DB_Password"));

Related

Can't connect to remote MySQL (MariaDB) database in .NET but I can with Java

I am trying to migrate some code from JavaFX to use C# for Windows Forms. In Java, I was using JDBC and could connect just fine programmatically. Nos that I am trying to use C# I am getting this error:
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server).
I am using the same server address and credentials. I'm using System.Data.SqlClient. I've tried a bunch of different combinations but can't get the connection string to work.
String connectionString = "server=[Server URL];database=[Database Name];persist security info=true;user id=[Username];pwd=[Password]";
Here is an example of the mysql connection string:
string connectionString = "datasource= <database ip or domain>; port=<port, usually 3306>;username=<database user>;password=<user's password>;SslMode=none<this is important if you don't use ssl>;database=<your database>";
I think the reason you can't connect is because you haven't specified the SslMode.

Why Connection timed error in redshift connection?

I want to connect aws redshift with aws lambda.
But this gives me error that connection timed out
Class.forName("com.amazon.redshift.jdbc42.Driver");
System.out.println("\n\nconnecting to database...\n\n");
connStringBuilder = "jdbc:redshift:iam://%s?AccessKeyID=%s&SecretAccessKey=%s&DbUser=%s&SessionToken=%s";
connString = String.format(connStringBuilder, redshiftClusterURL, accessKeyId, secret, dbUser, token);
System.out.println("connString is " + connString);
conn = DriverManager.getConnection(connString);
Just ensure these steps and let me know if your problem exists:
First Ensure that your aws lambda function is running in VPC if its running in VPC you
need to configure NAT gateway to connect to the internet and open the outbound port for the database
In redshift db open the inbound port for the specified IP ranges of your VPC.
If your aws lambda is not running in VPC.
Open the all traffic for specified db port in redshift (but it's not recommended and not safe too)

SQL Server secure JDBC connection without reconfiguring SQL Server for secure connections

How to connect SQL Server database instance via JDBC securely without altering the configuration of SQL Server where other connections access the server insecurely and it is not possible to change the configuration of the server?
I had some trouble connecting to SQL Server via Java JDBC using encryption. The method below supports a secure connection where the validity of the certificate is not checked. SQL Server will issue the certificate and use encryption. This method does not require other connections to the database to be secure and also does not require changes to the database server.
Just substitute your IP:port combination and your database instance in the statement below
url = "jdbc:sqlserver://x.x.x.x:1433;databaseName=yourDBname;" +
"integratedSecurity=false;encrypt=true;trustServerCertificate=true";
conn = DriverManager.getConnection(url, username, password);

how to solve connection between DB and Application

Currently I am working on a project using spring, hibernate with Microsoft SQL, in this project there is a part to generate invoice. When I run this part to generate invoice it take around 5 to 15 min then I retrieve invoice List from Db and show it in UI. I got exception after it process for around 7 to 10 min.
Note: When I check in Db , invoice is already generated.
How can I solve this issue?
The exception as follows:
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.191.19, port 1433 has failed. Error: "Address already in use: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
I think the driver may be the problem.
Try using jtds driver instead of microsoft dirver.
Check your connection url pattern.Here is sample connection url pattern.
jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks;integratedSecurity=true;

(Enterprise GlassFish v3 build 11) Communication link problem (MySQL DB)

I get a communication link failure while application tries to establish a connection with DB.
[#|2010-04-08T20:09:57.825+0300|SEVERE|glassfish3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=24;_ThreadName=Thread-1;|Cannot connect to database server = com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.|#]
Precisely at this string:
Statement s = conn.createStatement();
where conn is defined as follows:
private static java.sql.Connection conn;
For this app I have set a connection pool with default parameters and currently it (app) uses both JPA and direct JDBC queries. Recreation of connection pool gave nothing, connection pool ping gave next message:
Ping Connection Pool for pool is Failed. Ping failed Exce
ption - Connection could not be allocated because: Communications lin
k failure%%%EOL%%%%%%EOL%%%The last packet sent successfully to the s
erver was 0 milliseconds ago. The driver has not received any packets
from the server. Please check the server.log for more details.%%%EOL
%%%Ping failed Exception - Connection could not be allocated because:
Communications link failure
and flushing the connection pool gave:
com.sun.enterprise.admin.cli.CommandException: remote failure: Failed to flush connection pool ...
However I can connect to the database from a terminal. Besides I have the same app working on my local machine with identical connection pool settings.
Any one has an idea on whats going on or how to solve the trouble?
Such problem could be if you have mysql server & glassfish server on the same host, and in mysql configuration you have option bind to some public address (for example 192.168.0.1 of eth0 interface) that normally successfully working with simple jdbc/jpa using user#localhost, but they don`t in a case of glassfish JTA, instead to bind to some of local address you getting link failure. As rule you could not bind to any local (localhost/127.0.0.1) addresses of such mysql host if public address presented.
Example:
my.cnf
bind-address = 127.0.0.1
bind-address = 192.168.0.1
127.0.0.1 - assign to lo interface
192.168.0.1 - assign to eth0 interface
It is glassfish-mysql bug.
Currently in order to use JTA, you should not bind mysql to such address. (remove "bind-address=192.168.0.1" from my.cnf). Or use user#192.168.0.1 what is less secure.
Besides I have the same app working on my local machine with identical connection pool settings.
Are you connecting to the same database? If yes, maybe check that you're using the same JDBC driver.
In my case I set :
URL : jdbc:mysql://10.81.35.66:3306/testDB
and
url : jdbc:mysql://10.81.31.76:3306/vectordb
both When setting values while creating connection pool in additional property part
on glass fish admin console .

Categories