Issue connecting to SQL server using R2DBC and encrypted connection - r2dbc-mysql

Did anyone was able to connect to database using Spring boot, R2DBC and encrypted connection
I have a connection string:
jdbc:sqlserver://XXX.XX.XXXX:1433;encrypt=true;trustServerCertificate=true;databaseName=ABC
I am using connection factory builder class and parsed arguments as shown below:
public ConnectionFactory connectionFactory() {
final ConnectionFactoryOptions options = builder()
.option(DRIVER, "sqlserver")
.option(HOST, applicationDatabaseProperties.getHost())
.option(PORT, applicationDatabaseProperties.getPort())
.option(USER, applicationDatabaseProperties.getUsername())
.option(PASSWORD, applicationDatabaseProperties.getPassword())
.option(DATABASE, applicationDatabaseProperties.getDatabase())
.option(SSL, true)
.build()
return ConnectionFactories.get(options);
}
It gives me a runtime SSL error when I am trying to connect
I tried to add an option as shown below - I saw it in the documentation:
.option(Option.valueOf("[trustServerCertificate]","[true]"))
but compiler gives the error(using it from Kotlin code), I decompiled original class io.r2dbc.spi.ConnectionFactoryOptions
and trustServerCertificate is not listed as a constant
Any help would be greatly appreciated
Thanks, Sam
Tried adding the option .option(Option.valueOf("[trustServerCertificate]","[true]")) to the builder,
compiler returns the error

Related

Azure Cosmos DB - intermittent MongoConnectionException / IOException / SocketException

I'm using Azure Cosmos DB 4.0 with MongoDB C# Driver 2.10.4.
Most of the times the queries work fine, but I'm getting intermittent errors like this:
MongoDB.Driver.MongoConnectionException: An exception occurred while sending a message to the server.
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.BeginSend(...
at System.Net.Sockets.NetworkStream.BeginWrite
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.BeginWrite
at System.Net.Security._SslStream.StartWriting
at System.Net.Security._SslStream.ProcessWrite
at System.Net.Security._SslStream.BeginWrite
When that error happens the call takes 10-25 seconds before failing.
I'm building the MongoClient with new MongoClient(MongoClientSettings.FromConnectionString(cnstr)) and I was using the connectionstring with these arguments ?ssl=true&replicaSet=globaldb&retrywrites=false.
I tried with retryWrites=true (as per Azure Support suggestion) but that didn't help.
I tried different settings and that didn't work either (connect=direct, maxIdleTimeMS=30000, serverSelectionTimeout=5000ms, socketTimeout=10000ms).
What's causing those exceptions?
The fix was to set/force TLS 1.2 (based on this Microsoft document):
//return new MongoClient(connectionString);
var settings = MongoClientSettings.FromConnectionString(connectionString);
settings.SslSettings = new SslSettings()
{
EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12
};
return new MongoClient(settings);
Looks like although my connection string had ssl=true, it wasn't enough to work on some servers (the error is intermittent). The same underlying error can usually be fixed by forcing TLS 1.2 so I assumed that in Mongo it could be the same issue - and it really fixed the problem.

Npgsql throws an error: wrong connection string. Can't connect to postgreSQL [F#]

I'm using SQLProvider to connect to my (local) PostgreSQL database in F#.
I've started with this code from fsprojects:
open FSharp.Data.Sql
open Npgsql
let [<Literal>] ResolutionPath =
__SOURCE_DIRECTORY__ + #"/../../packages/Npgsql/lib/net451/"
[<Literal>]
let connectionString = "Host=localhost;Port=5432;User ID=test;Password=test;Database=testdb;"
type PostgreSQL =
SqlDataProvider<
Common.DatabaseProviderTypes.POSTGRESQL,
ConnectionString = connectionString,
ResolutionPath = ResolutionPath,
IndividualsAmount = 1000,
UseOptionTypes = true>
When I'm trying to compile it I get this error message:
(path)/Database.fs(60,9): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not create the connection, most likely this means that the connectionString is wrong. See error from Npgsql to troubleshoot: The type initializer for 'Npgsql.Counters' threw an exception.
(path)/Database.fs(60,9): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not create the connection, most likely this means that the connectionString is wrong. See error from Npgsql to troubleshoot: The type initializer for 'Npgsql.Counters' threw an exception.
I've checked that user id and password and everything in connection string is correct.
I actually don't have any idea how to debug this issue.
Do you know what could be wrong?
Does it work for you without any issues?
I'm using macOS 10.12.
And lastly, in case I won't be able to fix this, are there any other methods that you would recommend for connecting to postgreSQL (with type providers)?
The error message clearly says that an exception was thrown from the type initializer for Npgsql.Counters - this is Npgsql 3.2's new support for Windows performance counters.
Unfortunately it seems that there are several issues with performance counters in various scenario (see #1447 and #1435). Because of this, version 3.2.2 (to be released this week) won't make use of them by default.
Can you please confirm that you're using 3.2.1 (and not 3.2.0), because a partial fix was introduced? If you're using 3.2.1 and getting this exception, you'll have to wait a few days for 3.2.0, and can use 3.1.10 in the meantime where the exception won't be thrown.

How can I connect vertica with JDBC?

I want to connect vertica with JDBC. But I got errors.
Here is my code :
....
Class.forName("com.vertica.jdbc.Driver");
....
connection= DriverManager.getConnection
(
"jdbc:vertica://192.168.2.116:5433/schema", "dbadmin", "pass123"
);
But I got this error(if I open the netbeans database section I got same error message. But I connect to vertica with client(Dbeaver)) :
ex = (java.sql.SQLException) java.sql.SQLException: [Vertica]No enum const class com.vertica.dsi.dataengine.utilities.MetadataSourceColumnTag.COLUMN_SİZE
How can I fix this?
So if you need jdbc client for vertica in netbeans or intellij use this vertica jdbc driver. It's the one that worked for me. (taken from dbvisuzlizer).
i think it is because of your locale. in this case turkish i guess.
COLUMN_SİZE has upper case i -> İ
it is verticas fault to use toUpper digressivly.
Vertica's connect string uses databasename, not schema name after the host:port. See the doc for details:
https://my.vertica.com/docs/CE/6.0.1/HTML/index.htm#1395.htm
Connection conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:portNumber/databaseName",
"username", "password");
By default, users have a search path of "$user, public, v_catalog, v_monitor and v_internal", therefore, you can create and use a matching username to connect directly to the desired SCHEMA.
Its about 32 bit - 64 bit issue I think, because it is working on 32 bit windows I cant understand
make sure the connector (vertica-jdbc-xxxx.jar) is in the JDK\jre\lib\ext folder

Sql Azure Connection String error

I am trying to connect to Sql Azure use the ADO.net connection still provided by the portal. It is of the format
var connectionstring =
"Server=tcp:abcdefghij.database.windows.net,1433;Database=[myDatabase];User ID=[myName]#abcdefghij;Password=[]myPassWord;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
When I pass this connection string to the DbContext constructor it falls over. The error message is
"The type initializer for 'System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions' threw an exception."
Any ideas what the problem can be?
Thanks
Martin

GWT JDBC LDAP connection fails

I am trying to connect my GWT application to an ldap server using jdbc, but could not make it work so far.
Here is a code sample of my attempt to connect to it:
String ldapConnectString = "jdbc:ldap://SERVERIP:389/dc=SERVERNAME,dc=office,dc=COMPANY,dc=com?SEARCH_SCOPE:=subTreeScope";
java.sql.Connection con;
try {
con = DriverManager.getConnection(ldapConnectString,"cn=USERNAME","PASSWORD");
} catch (SQLException e) {
System.out.println("An error has ocurred!!! Connection failed");
e.printStackTrace();
}
The example I used to write this is: http://myvd.sourceforge.net/bridge.html
When I run the application I get following error message:
java.sql.SQLException: No suitable driver found for jdbc:ldap://SERVERIP:389/dc=SERVERNAME,dc=office,dc=COMPANY,dc=com?SEARCH_SCOPE:=subTreeScope
I would be thankful for any help
Edit:
The code sample I provided is running on server side accessed by RPC. I included 2 jar files in my lib/ directory downloaded from here: http://sourceforge.net/projects/myvd/files/jdbc%20ldap%20bridge/jdbc%20ldap%20bridge%202.1/jdbc-ldap-2.1.zip/download
You generally need to register the JDBC driver before you can connect to the backend.
Try something like
DriverManager.registerDriver(new com.octetstring.jdbcLdap.sql.JdbcLdapDriver());
before setting up the connection.
More general information on ways of registering drivers.