SQLServer authentication exception by jdbc - java

i'm trying to connect to a newly installed SQLServer instance by my java application using jdbc.
When i try to open a connection the server return this error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'.
Error Stack trace:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerE‌​xception.java:197) at
com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
I've already enabled "SQL Server and Windows Authentication mode" option.
I also tried to connect to the database server with SquirreL but i had the same problem, but with SQL Server Management Studio i can connect to the db.
I have a SQLServer 2008 R2 express, jdk 6u41 and sqljdbc4.jar JDBC connectors.
I've tried the same application in an environment with SQLServer 2008 R2 express, jdk 6u33 and sqljdbc4.jar JDBC connectors and it work fine.
Are there some SQL server configuration that i need to modify?

I think, you have configured the SQL Server in Windows Authentication mode on the time of installation but, changing the settings in the program would not change it from Windows Authentication mode.
Can you do one thing? Remove the SQL Server 2008 and all related programs from your machine and install a fresh copy, this time with SQL Server Authentication. It will work...

Related

Azure SQL database connection issue from an Azure VM by Java JDBC

We have a java project in an Azure virtual machine (VM), and need connect to Azure SQL db by JDBC connection, so we use the JDBC connection string provided by Azure SQL db as follows:
"jdbc:sqlserver://ZZZdbserver.database.windows.net:1433;database=ZZZ;user=*****;password=*****;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;"
but we got an exception:
"java.security.cert.CertificateException: Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization.
The server name is *.database.windows.net, the name in certificate is cr2.eastus1-a.control.database.windows.net."
then we updated the JDBC connection string to:
"jdbc:sqlserver://ZZZdbserver.database.windows.net:1433;database=ZZZ;user=*****;password=*****;encrypt=true;trustServerCertificate=false;hostNameInCertificate=cr2.eastus1-a.control.database.windows.net;loginTimeout=30;"
but we got another exception:
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Cannot open server "ZZZ1" requested by the login. The login failed.)
where "ZZZ1" is our username for the Azure VM.
Any idea to solve this issue?
By default, Azure VM has not blocked the outbound connection to the Internet. You could first verify the network connectivity from your VM to the Azure SQL database via running the command telnet ZZZdbserver.database.windows.net 1433 in CMD or Test-NetConnection -computer ZZZdbserver.database.windows.net -port 1433 in Powershell. If it fails, you may check if there is any firewall blocking this database connection or port or your application is listening on that port or your SQL database is online.
Additionally, if the network connectivity has succeeded, you could verify if the username or password is correct when you are using to connect to your database. Make sure there is not any typo. Also, the username should have enough privileges to access this database. You can try to access this database via Server admin login in the properties of the SQL database. Moreover, you could refer to this sample code to use Java to connect to access the Azure SQL database.
When using the Microsoft JDBC Driver for SQL Server to connect to an Azure SQL Database. You should note this:
Appending the server name to the userId in the connection string
Prior to the 4.0 version of the Microsoft JDBC Driver for SQL Server,
when connecting to an Azure SQL Database, you were required to append
the server name to the UserId in the connection string. For example,
user#servername. Beginning in version 4.0 of the Microsoft JDBC Driver
for SQL Server, it's no longer necessary to append #servername to the
UserId in the connection string.
Using encryption requires setting hostNameInCertificate
Prior to the 7.2 version of the Microsoft JDBC Driver for SQL Server,
when connecting to an Azure SQL Database, you should specify
hostNameInCertificate if you specify encrypt=true (If the server name
in the connection string is shortName.domainName, set the
hostNameInCertificate property to *.domainName.). This property is
optional as of version 7.2 of the driver.
Hope this helps.
If I need set encrypt=true, and hostNameInCertificate=cr2.eastus1-a.control.database.windows.net. Where do I need get the certificate for cr2.eastus1-a.control.database.windows.net from Azure SQL DB's service?

MyEclipse Professional on connecting with ms sql server is giving ssl error through db browser

I am using MyEclipse professional and trying to connect with the MS SQL SERVER 2016, i am using the jar file sqljdbc4-4.0 and driver
“class name= com.microsoft.sqlserver.jdbc.SQLServerDriver”
My connection URL is jdbc:sqlserver://hamdan:1433;databaseName=DWProject
where hamdan is the SQL server name, after giving the credentials i got the error of error while performing database login with the mysqlserver driver: the driver couldn't establish a secure connection to SQL server by using secure socket layer(SSL) encryption. Error java.lang.runtimeException, could not generate DH keypair.
However i have also set Force Encryption to "NO" in the protocol for sql server's properties in sql server configuration.
when i am changing the jar with the jar present on this link https://www.microsoft.com/en-us/download/details.aspx?id=11774 which is jdbc 6.0 and using jar for jre 8 which is sqljdbc42, i get error of driver class not found while using new database connection driver.
Any help will be highly appreciated, i am on this from more than one day,
I am new to eclipse.
This is the problem in windows 10, it encrypts the link between eclipse and SQL Server, so you should use latest myeclipse or try in different OS

Connect to SQL Server from Linux via JDBC using integratedSecurity (Windows authentication)?

Hey I am having trouble connecting to an SQL Server with Java code that is running on Linux.
If I set integratedSecurity=true, then the java code fails with the following error:
WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:b030b480-453d-4007-8151-a552150f74cd
which makes sense as there will be no sqljdbc.dll file on Linux.
But if I set integratedSecurity=false, then I get the following error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'IT_DEV_USER'.
So does anyone know how I can connect to SQL Server with integratedSecurity set to false? (Note that I cant even connect when the Java code is running on Windows when integratedSecurity is set to false.)
If not, is there any way I can get integratedSecurity working on Linux?
If you want to use integrated security and using JDBC Driver 4.0 or greater then you add the following in your jdbc connection string.
integratedSecurity=true;authenticationScheme=JavaKerberos
More information: http://blogs.msdn.com/b/psssql/archive/2015/01/09/jdbc-this-driver-is-not-configured-for-integrated-authentication.aspx
Adding authenticationScheme=JavaKerberos works for me in Linux, but make sure to remove integratedSecurity=true since you are not using Windows.
You can't use integratedSecurity feature from Linux system, as it tied to windows system and uses your windows authentication. However, if you enable both SQL Server and Windows Authentication mode on your SQL Server, then you can create a login, map to corresponding database and use it in java from Linux.
To enable SQL Server authentication:
Right click on your server in management studio
Properties
Security
Server authentication -> SQL Server and Windows Authentication mode
If you dont want Integrated Security connection, then set that parameter to false and instead provide user and password in the connURL as below:
String connectionUrl = "jdbc:sqlserver://localhost:port;databaseName=DB_NAME;integratedSecurity=false;user=login_user;password=login_pwd;";

Getting JDBC drivers compatibility issue. java.sql.SQLException: ORA-06413: Connection not open

I am getting below exception with Oracle JDBC ojdbc14_g.jar drivers:
java.sql.SQLException: ORA-06413: Connection not open.
My Oracle version is:
My machine and server details are:
I am able to connect to production DB from my development environment, but after installing application in production server my application is unable to connect to locally installed database. I am getting above said exception.
Below is my connection URL:
jdbc:oracle:oci8:#127.0.0.1:1521:XE
Try to replace oci8 with thin. JDBC over (native) OCI require some knowledge and experience. You have to install and configure Oracle client 1st.
See http://docs.oracle.com/cd/B28359_01/java.111/b31224/instclnt.htm

Netbean Service with Sql Server 2008

I have been trying to connect netbean service for database explorer with Microsoft SQL Server JDBC Driver 3.0 but unsuccessful always.The zipped jdbc driver has two jars I tested it with sqljdbc but it says that is is not compatible with java 1.7 so I tried it with sqljdbc4 and now it shows following error:
I have enable TCP/IP connection to the server.
What is the right way to connect netbean service with sql server 2008?
I got the solution to this problem actuall you should use the port 57634 for TCP/IP connections. Well you can change the port if you want by going to :
Configuration Manager -> Protocols for SQL SQLEXPRESS > Properties of TCP/IP. In the IP Addresses tab, set the TCPPort in section IPAll to 1433.

Categories

Resources