I have an application running on a server and I'm using H2 database for that,
This my database URL:
jdbc:h2:./cafeDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=7080
And I want to connect to this database using Intellj idea's database tools, this is my configuration:
But when I try to connect, It keeps asking me the DB's username and password, and even when I put the correct information and submit it says:
The specified database user/password combination is rejected: [28000][28000] Wrong user name or password [28000-200]
Am I doing something wrong?
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 using Sequel Pro 1.1.2 in MacOS Mojave, when trying to configure the AWS database instance getting error as
" Unable to connect to host vinay-awsdb.cinbpy8tpejb.eu-west-1.rds.amazonaws.com, or the request timed out.
Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).
MySQL said: Can't connect to MySQL server on 'vinay-awsdb.cinbpy8tpejb.eu-west-1.rds.amazonaws.com' (4)"
In the standard connection mac for Sequel Pro,I am entering the following:
Name: (used my instance name which is vinns, and also tried leaving it with the default of 'optional')
Host:vinay-awsdb.cinbpy8tpejb.eu-west-1.rds.amazonaws.com
Username: (used my master user name)
Password: (used my master users password)
Database: (used database name mydbname, and also tried leaving it with the default of 'optional')
Port:3306
I am not able to connect.
I also tried by changing the Inbound rules to anywhere and increased connection timeout to 60 but did not worked
I am trying to connect to my database using JDBC driver. I have to use my another windows domain credential to connect and getting login failed error. Thought of testing it with my actual windows credential and it worked. I have used integratedSecurity = true.
String connectionUrl = "jdbc:sqlserver://server;databaseName=DB;integratedSecurity=true";
My desired connection string to use my another windows domain credential looks like the below:
String connectionUrl = "jdbc:sqlserver://server;databaseName=DB;user=domain\\user;password=test!123;"
I did the following things and in need of help:
Placed the sqljdbc_auth inside jdk/bin and jre/bin
SQL Server has been kept under the mixed auth mode (both Windows and SQL Auth).
Using my another domain ID, I tried to execute a query in MS SQL Studio and it worked.
Using the Microsoft JDBC driver, you can:
Connect with SQL Auth, using user and password
Connect with Window Auth, using integratedSecurity=true, which will use the Windows user that is running the Java program
Connect with Kerberos Auth, but that is complex to setup: Using Kerberos Integrated Authentication to Connect to SQL Server
If you want to do a simple NTLM connect using domain, user and password, then you need to use the jTDS JDBC driver.
I want to be able to connect to a SQL Server using jdbc and windows authentication.
I saw some answers on the internet saying i should add the following property to the connection string:
integratedSecurity=true;
And also add
sqljdbc_auth.dll
To the java path.
But this, as far as i understand applies only when i'm connecting from a Windows machine.
When i try this on a Linux machine i get:
java.sql.SQLException: This driver is not configured for integrated authentication
My question is how do I do it from a Linux machine.
Thanks
Well, eventually I answer my own question:
This is not possible to use Windows authentication from a linux machine using the Microsoft JDBC driver.
This is possible using the jTDS JDBC driver using the following connection string:
jdbc:jtds:sqlserver://host:port;databaseName=dbname;domain=domainName;useNTLMv2=true;
Thank you all for all the comments
TL;DR
It is not possible to use native Windows Authentication for JDBC connections to MSSQL from a JVM running on Linux.
This MSDN article explains the authentiation methods with JDBC on Linux, potential errors, and available options:
https://blogs.msdn.microsoft.com/psssql/2015/01/09/jdbc-this-driver-is-not-configured-for-integrated-authentication/
...in the JDBC 4.0 driver, you can use the authenticationScheme
connection property to indicate how you want to use Kerberos to
connect to SQL. There are two settings here.
NativeAuthentication (default) – This uses the sqljdbc_auth.dll and is specific to the Windows platform. This was the only option
prior to the JDBC 4.0 driver.
JavaKerberos – Makes use of the Java API’s to invoke kerberos and does not rely on the Windows Platform. This is java specific and not
bound to the underlying operating system, so this can be used on both
Windows and Linux platforms.
...
The following document outlines how to use Kerberos with the JDBC
Driver and walks through what is needed to get JavaKerberos working
properly.
Using Kerberos Integrated Authentication to Connect to SQL Server
http://msdn.microsoft.com/en-us/library/gg558122%28v=sql.110%29.aspx
For those who are using DBeaver the way to connect to the SQL Server Database is:
In order to connect to the SQL Server from Linux Debian using DBeaver
1.- Select SQL Server jTDS driver
2.- Enter the connection information
3.- Go to Driver Properties tab and add the domain, user, password
Just as a note, in some post I found that they needed to change the property USENTLMV2 to TRUE but it worked for me either by putting the USERTLNMV2 in true or false.
A problem that I found was that when I was trying to connect to the database using my user and password the next error was thrown:
Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
This error was thrown because of my user was about to expire. I tried with another AD user and it could connect.
I know this is kind of an older topic but in case Google sends people here:
There are two main JDBC drivers for SQL Server. One is from Microsoft and the other from jTDS. jTDS can, amazingly, connect using Windows auth (NTLM) from other platforms, including Linux, as described here: http://jtds.sourceforge.net/faq.html#windowsAuth. It can, of course, also use SQL-authenticated logins. SQL-authenticated logins are no harder to use from any OS than any other, so don't forget about those an option.
The version provided by Microsoft is the one from which #mjn provided a quote from the documentation. It is able to connect using Windows authentication by specifying integratedSecurity=true, authenticationScheme=javaKerberos, and authentication=NotSpecified.
It is tricky to get this working even if you don't go out of your way to find more confusion, so always keep in mind which driver you are using - and tell us in these posts so that you can get more specific help.
This JDBC URL is validated to work with latest Microsoft SQL Server JDBC driver:
jdbc:sqlserver://[server]:[port];database=[db\;trustServerCertificate=true;integratedSecurity=true;user=[user without domain];password=[pw];authenticationScheme=NTLM;domain=[domain];authentication=NotSpecified
Example:
jdbc:sqlserver://mysql.myorg.com:1433;database=mydb;trustServerCertificate=true;integratedSecurity=true;user=myuser;password=mypwd;authenticationScheme=NTLM;domain=ad.myorg.com;authentication=NotSpecified
I was able to connect to a SQL Server 2016 Data Mart and JDBC connection Microsoft JDBC Driver using Windows Authentication using the following script on a Ubuntu Linux Docker Image running on Windows 10.
# initializes spark session
from pyspark.sql import SparkSession
spark = SparkSession\
.builder\
.master('local[*]')\
.appName('FDM')\
.config("spark.driver.extraClassPath","pyspark_jars/*")\
.config('spark.executor.memory', '4g')\
.config('spark.driver.memory', '16g')\
.config('spark.executor.cores', '4')\
.getOrCreate()
jdbc_url = '''jdbc:sqlserver://SERVER;databaseName=DBNAME;trustServerCertificate=true;integratedSecurity=true;user=USERID;password=PASSWORD;authenticationScheme=NTLM;domain=US;authentication=NotSpecified'''
spark_df = spark.read\
.format("jdbc")\
.option("url", jdbc_url)\
.option("driver","com.microsoft.sqlserver.jdbc.SQLServerDriver")\
.option("query", 'select top(1000) * from SCHEMA.TABLE')\
.option("fetchsize", 100000)\
.load()
spark_df.write.csv('TEST.csv', mode = "overwrite", header=True)