The best documentation I have been able to find about how to create a JDBC URL for an SQL Server instance within Cloud SQL is located here: https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory
The only problem is, there is no example or instructions for creating the JDBC URL for SQL Server.
I have tried some obvious possible solutions, none of which have worked - for example:
jdbc:sqlserver:///<DATABASE_NAME>;socketFactory=com.google.cloud.sql.sqlserver.SocketFactory;cloudSqlInstance=<INSTANCE_CONNECTION_NAME>;user=<USER_NAME>;password=<PASSWORD>
I have a mysql server in the same project that I am able to connect to with no issue (after updating the jdbc Driver and JDBC URL). SQL Admin API is enabled and GOOGLE_APPLICATOIN_CREDENTIALS is pointing to the correct service account.
Relevant pom.xml
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>cloud-sql-connector-jdbc-sqlserver</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.4.0.jre8</version>
</dependency>
If i'm reading the git repo correctly it actually looks like JDBC support for SQL Server was just added in the 1.2.0 release - has anyone been able to get this to work?
https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/pull/263
Error I am receiving
ERROR: The TCP/IP connection to the host /<DATABASE_NAME>, port 1433 has failed. Error: "/<DATABASE_NAME>. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."
Thanks!
The root cause was that the version of SQLServerDriver I was using does not appear to compatible with com.google.cloud.sql.sqlserver.SocketFactory. I was able to switch to the net.sourceforge.jtds.jdbc.Driver which worked as expected. More info in this thread: https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/issues/373
Related
I try to make a connection to an SQL server from my Spring Boot application.
I receive this error when starting my application:
jdbc.SQLServerException: The TCP/IP connection to the host MSSQLSERVER01, port 63251 has failed.
Error: "MSSQLSERVER01. Verify the connection properties.
Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port.
Make sure that TCP connections to the port are not blocked by a firewall.".
This is my application.properties
spring.datasource.url=jdbc:sqlserver://MSSQLSERVER01;DatabaseName=learning;port=63251
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.username=dbo
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
I wasn't allowed to paste my pom.xml file here, since it said that my post consisted mainly of code instead of explanation, which it wouldn't allow. Here is the link to my pom.xml: https://justpaste.it/99k7a
Any ideas on what I have done wrong? I am new to Java and Spring Boot, btw. Thanks in advance.
I am trying to connect the spring boot application I have created locally to an aws serverless aurora database.
I have added the maven dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
As well as created an application.properties file:
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://myawsclusterlink:3306/mycluster
spring.datasource.username=myusername
spring.datasource.password=mypassword
spring.datasource.hikari.minimum-idle=0
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.max-lifetime=90000
spring.datasource.hikari.idle-timeout=90000
I have also created a VPC inbounds group for the db to allow incoming traffic from my IP address.
My Issue is that that when I run the app, my connection keeps failing with an error message:
com.mysql.cj.jdbc.exceptions.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.
I would like to know where is the problem. Is my url wrong? Have I not enabled something on aws? Is there something missing in my code?
Also, I don't really know how to test and see where the problem is coming from in this case.
Changing from serverless to provisioned aurora and enabling public access solved the issue
I am trying to connect to a MS SQL Server database using Java but I keep running into the same error.
I am using MS SQL Server for developers and am maniging it through SSMS. When I installed it I set is so it would use my windows credentials as password.
The JDBC driver is added to my project as a Maven dependency.
From what I understand reading the Microsoft doc's I should be able to use the following connection string:
String connectionUrl ="jdbc:sqlserver://localhost;integratedSecurity=true";
However this does not seem to work for me as it returns SQLState 08001. After reading up on this state I understand that it has something to do with failing to make the connection.
I also tried to form my connection string using my windows login name, which results in the same:
String connectionUrl = "jdbc:sqlserver:localhost:1433;databaseName=DBNAME;user=John Doe;password=0123456789";
I also tried to create a login using T-SQL to use as credentials using the same string as the previous (only changing the username and password):
CREATE ROLE [USER]
GRANT SELECT, INSERT ON SCHEMA :: [dbo] TO USERNAME
CREATE LOGIN USERNAME_LOGIN WITH PASSWORD = '1234567890'
CREATE USER USER_USERNAME FROM LOGIN USERNAME_LOGIN
ALTER ROLE [USER] ADD MEMBER USER_USERNAME
I could really use some help to understand what I am doing wrong and what I can do to make it work. If you require me to check anything please let me know how as I am still pretty new to this.
Edit
As requested here is the info coming from getMessage():
No suitable driver found for
jdbc:sqlserver:localhost:1433;databaseName=.....
I am guessing this would also be the moment to mention the Maven dependency I am importing:
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.3.0.jre8-preview</version>
</dependency>
I think the question now becomes, do I have the wrong driver as a dependency for MS SQL Server 2017?
I turned out I did not had TCP/IP connections enabled for MS SQL Server.
To enable this in MS SQL Server 2017:
Start SQLServerManager14.msc from the windows application menu.
Go to SQL Server Network Configuration.
Go to Protocols for YOURINSTANCE.
Set TCP/IP to enabled.
I am developing a simple JAVA Time triggered Azure Function.
I am trying to connect to a Azure MySQL instance but I keep getting this error:
[Information] com.mysql.cj.jdbc.exceptions.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.
Here is the source code:
String url="jdbc:mysql://XXXX.mysql.database.azure.com:3306/DBNAME?useSSL=true&requireSSL=false";
connect = DriverManager.getConnection(url, "user#DBNAME", "passwd");
statement = connect.createStatement();
resultSet statement.executeQuery("select * from table1");
I am using the following library:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
Notes:
The program works fine on my local machine (i.e., after adding my IP address to the MySQL firewall, I can reach the DB from my machine);
I've already tried different mysql libraries: nothing changes;
Another Azure function implemented with NodeJS is able to reach the DB;
I tried to add the Function "ADDITIONAL OUTBOUND IP ADDRESSES" to the MySQL firewall: nothing changes.
Any ideas?
Thank you in advance.
5.1.31 MySQL-connector-java version Worked for me.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.31</version>
</dependency>
Connecting MySQL Azure with Java
I am using a domain user account to connect to SQL server database and when I try to start my server I get the exception com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user error. I am using sqljdbc4-1.0.jar drivers.
The userid I am using is a service user id (a domain user id) which is different from the userid I am logged into windows. So I cannot use IntegratedSecurity option. my connection url looks like
jdbc:sqlserver://server;authentication=SqlPassword;userName=domain\username;password=mypassword;databaseName=mydatabase;
I even tried providing the username and password separately and even that also did not work. I searched a lot but could not find any relevant help. Please help.
I recently had the same problem with java app(Spring Boot) connecting with a domain user and wasting a few days doing it, but I managed, here's how I did it, hope it helps:
pom.xml:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
properties file:
jdbc:jtds:sqlserver://host:port;databaseName=dbname;instance=SQLDEV;domain=domainname.corp;user=userdb;password=p4ssw0rd;
example:
my file has too many options remove it if you don't use it
spring.application.name=app-name
spring.profiles.active=dev
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.url=jdbc:jtds:sqlserver://100.50.50.56/MinWeb;instance=SQLDEV;domain=domainname.corp;user=userdb;password=password;
spring.datasource.test-while-idle=true
spring.datasource.validation-query=SELECT 1
spring.datasource.time-between-eviction-runs-millis=60000
spring.datasource.remove-abandoned=true
spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
spring.jpa.properties.hibernate.hbm2ddl.auto=none
Here are some links that I consulted:
Connect To SQL Server With Windows Authentication From A Linux Machine Through JDBC
Configure HikariCP in Spring Boot with JTDS
Create a jTDS connection string
T+