How to connect to sql DB from soapUI using connection string? - sql-server

I would like to ask someone who already tried to connect to SQL database from soapUI opensource version.
I have a test step JDBC request where I try to test and connect to my sql database. I use opensource version of soapUI. I read how it should be set up but still experience some problems.
This is what I do:
I installed java 8 and jdbc driver version 4.1. Added jdbc jar file to SoapUi/jre/bin folder as it is said in documentation for soapUI. This version of driver should work with Java 8.
Then in Driver field I write
com.microsoft.sqlserver.jdbc.SQLServerDriver
In connection string:
jdbc:sqlserver://Sservername:portnumber;databaseName=Consumption;username=alyona.kovalyova;password=mypassword
I get error saying
Can't get the Connection for specified properties; com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'alyona.kovalyova'. ClientConnectionId...
I use my domain account because in our company the policy does not allow us to use database user. Because of this I tried to add integratedSecurity parameter to the string which should allow to login with windows account like this:
jdbc:sqlserver://S23-AS:1433;databaseName=Consumption;integratedSecurity=true
I also get error:
Can't get the Connection for specified properties; com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId..
Does anyone encountered the same issue before? Could you give some recommendation?

For integrated authentication to work you'll need sqljdbc_auth.dll matching your environment (32bit / 64bit) in your library path (putting it in bin as well might help already)

Related

Microsoft SQL server as Atrifactory 7.38.10 metadata database

We have installed Atrifactory 7.38.10 on a windows server, Microsoft SQL server configured in System.yml as a database for metadata.
String connectionUrl =
"jdbc:sqlserver://localhost:1433;" +
"databaseName=AdventureWorks;integratedSecurity=true;" +
"encrypt=true;trustServerCertificate=true";
Artifactory.bat start throwing below mentioned error.
Could not initialize database (db config: {mssql jdbc:sqlserver://dev.tfs2017sql.xyz.com:55300;databaseName=JFROGPOC;encrypt=false;sendStringParametersAsUnicode=false;applicationName=Artifactory Binary Repository;integratedSecurity=true;}): TLS Handshake failed: x509: certificate signed by unknown authority
error connecting to database. giving up
jfrog.com/metadata/v7/services/common/db.(*databaseBearer).init
jfrog.com/metadata/v7#v7.37.0/services/common/db/database_bearer.go:152
Java version is 11 and JDBC driver is “mssql-jdbc_auth-10.2.1.x64.dll” for windows integrated authentication
From the way it looks, the issue is on the metadata service as you said.
I suggest trying to follow this article I wrote in the past about it and try to provide to the metadata service an additional golang connection URL(as it's possible that the script conversion from the Java doesn't support all the parameters), and make sure you have added the certificate to the /etc/ssl/certs folder as metadata service is written in Golang and usually load the certificates from the OS and not from the Java trust store.

SQL Server log in failing from Java DriverManager.getConnection(), working from Python with pymssql.connect()

I'm trying to use DriverManager.getConnection() to connect to a SQL Server db from a Java application, but I keep getting "Login failed for user" errors with it. I've tried using both com.microsoft.sqlserver.jdbc.SQLServerDriver and net.sourceforge.jtds.jdbc.Driver to connect, but both keep hitting the issue.
Here's the code I'm using to connect:
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:jtds:sqlserver://SERVERADDRESS:1433;DatabaseName=DBNAME;user=USER;password=PASS");
I know that account has access to that DB, as I've connected to it before from a Python application using pymssql.connect(SERVERADDRESS, USER, PASS, DBNAME) with the same server/DB/creds.
From this article, I eventually managed to get it working using windows authentication with my personal account, but I still can't get it to work using our service account. Does anyone have any insight into why the Python app can connect but the Java one can't?
pymssql is built on top of FreeTDS. Both FreeTDS and jTDS support an older Windows authentication scheme named NTLM, while current versions of Microsoft's JDBC Driver for SQL Server (mssql-jdbc) no longer support that authentication mechanism.
So, given that you've confirmed that pymssql can connect, you should be able to connect from your Java app as Windows user MYDOMAIN\username using jTDS like so:
String myUid = "username", myPwd = "mypassword";
String connUrl = "jdbc:jtds:sqlserver://192.168.1.123:1433/databasename;DOMAIN=MYDOMAIN";
Connection conn = DriverManager.getConnection(connUrl, myUid, myPwd);
To find out the reason of "Login failed for user" one should go to SQL Server error log.
The next row to 18456 error will give you the reason.
The most probably reason of failure in your case is that the server is configurated to use Windows Authentication only

JDBC URL connection to SQL Server using Windows Authentication in JIRA plugin

I am currently at my wits end. I am trying to connect a JIRA plugin (Atlassian Java SDK) to a SQL Server 2012 database. It's required that I use Windows Authentication, but JIRA is logging:
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication.
I've read that this can be combatted by adding the sqljdbc_auth.dll file to the program's library path, but there are no references specifically for JIRA plugins on how to do this other than for the base JIRA dbconfig.xml, which I am not using. This is a connection made within the plugin using the code:
String url = String.format("jdbc:sqlserver://%s:1433;databaseName=%s;integratedSecurity=true;domain=XXXX;", server, database);
I have tried to add the dll file to the following locations, all to no avail:
C:/{JIRA INSTALL PATH}/bin
C:/{JIRA INSTALL PATH}/jre/bin
C:/{JAVA INSTALL PATH}/jre_8.x.x/bin
What gives?
UPDATE:
I have gone in and added the JDBC JAR/DLL to the classpath/library path respectively in the JIRA Windows service configuration tool. Still getting the same error.
UPDATE 2:
I have switched to using the JTDS driver to see if JIRA was just not able to use the standard JDBC driver for some reason, but getting a similar error:
java.sql.SQLException: I/O Error: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.
I have also created a new Java app to test this in a controlled environment, but do not get this error after adding the ntlmauth.dll file to the C:\Windows\System32 directory. This leads me to believe this may be a bug within JIRA or I have something configured improperly.
Here is my own conclusion after many weeks of searching:
It is (currently) impossible to do this without the use of a password (which is sometimes the entire point of using Windows/Active Directory credentials). You can however use the JTDS driver in junction with a domain, username, and password to authenticate to servers that require windows authentication. This does not solve the core issue, but from what I can tell is the only current solution close enough to it.

Sonarqube 5.2 SQLServer connection

Since Sonarqube 5.2 is released, the jTDS JDBC driver is no longer supported. We used this driver to connect to our SQLServer instance, but we'll have to switch to the Microsoft SQLServer driver. We're running Sonarqube on Ubuntu and use an Active Directory account to connect to the SQLServer database. Because we're running on Ubuntu we can't use integrated security, so the credentials have to be supplied in the JDBC configuration for Sonarqube. This would result in the following properties:
sonar.jdbc.url=jdbc:sqlserver://sqlserverhost.my.domain.com:1433;databaseName=sonar;selectMethod=cursor
sonar.jdbc.username=someuser
sonar.jdbc.password=somepassword
This results in SQLServer in a "Login Failed" with the message "Could not find a login matching the name provided."
The next thing I tried was to connect with a username containing the domain, resulting in these properties:
sonar.jdbc.url=jdbc:sqlserver://sqlserverhost.my.domain.com:1433;databaseName=sonar;selectMethod=cursor
sonar.jdbc.username=DOMAIN\\someuser
sonar.jdbc.password=somepassword
This however also results in a "Login Failed" in SQLServer, the message here is "Attempting to use an NT account name with SQL Server Authentication."
What am I missing?
UPDATE:
The Sonarqube log can be found here: http://pastebin.com/AGB9bTQG
I can think of one thing which is different from the jTDS connection url:
the jTDS connection url contained ";domain=my.domain.com", which the Microsoft SQLServer driver doesn't seem to support. Therefore I tried the DOMAIN\someuser setup which SQLServer refused.
The driver is completely different from the jtds driver. In order to use it, you'll need to specify the authenticationScheme=JavaKerberos parameter (please refer to https://msdn.microsoft.com/en-us/library/gg558122(v=sql.110).aspx and http://blogs.msdn.com/b/psssql/archive/2015/01/09/jdbc-this-driver-is-not-configured-for-integrated-authentication.aspx)
The problem here is that your Linux machine is most likely not in the same domain, so you'll need to configure kerberos on your Linux machine too. Your best bet would really be mixed mode.
The connection string format has changed. No more :1443 or selectMethod
sonar.jdbc.url=jdbc:sqlserver://sqlserverhost.my.domain.com;databaseName=sonar
The connection string setting needs to be in the format:
sonar.jbc.url=jdbc:sqlserver://{server}:{port #};databaseName={db name}
e.g.
sonar.jbc.url=jdbc:sqlserver://localhost:36549;databaseName=Sonar
Check in SQL Server Configuration Manager that TCP/IP protocol is enabled and to find the port number for the SQL instance you want to connect to. Note that the database name in the connection string is case sensitive and must match what appears in SSMS.
Re: Windows Auth to SQL Server - you need to either use a SQL Server Auth user, or comment out sonar.jdbc.username and sonar.jdbc.password so that the SonarQube makes the connection under the credentials of the user running the SonarQube service; I don't think it supports impersonation.
Our solution was to have a SQL Server account created with permission to the database and use that instead of using the AD/Windows account.

I/O Error: SSO Failed: SSPI Not Initialized

I am using pentaho data integration 4.1 (Kettle) to build an ETL system. My customer requires connecting to database (MS SQL Server) using window authentication, I knew that Kettle supported it . However when I run my Kettle job, it throws the exception
"I/O Error: SSO Failed: SSPI Not Initialized".
From an article on a forum, I copy library sqljdbc_auth.dll into jre/bin folder. The result is quite good, I can use window authentication to connect to SQL server. But this function is not stable, I mean sometimes it works well, sometimes it throws exception
"I/O Error: SSO Failed: SSPI Not Initialized".
Please tell me how to fix this error.
Thank you.
To connect to SQL Server 2008, I had to install the 'Microsoft JDBC Driver 4.0 for SQL Server' and then add the path to sqljdbc_auth.dll to Spoon.bat in %PENTAHO_DI_JAVA_OPTIONS%. Like this:
set OPT=%PENTAHO_DI_JAVA_OPTIONS% "-Djava.library.path=%LIBSPATH%;C:\PROGRA~1\MICROS~1.0FO\sqljdbc_4.0\enu\auth\x86;C:\PROGRA~1\IBM\SQLLIB\BIN" "-DKETTLE_HOME=%KETTLE_HOME%" "-DKETTLE_REPOSITORY=%KETTLE_REPOSITORY%" "-DKETTLE_USER=%KETTLE_USER%" "-DKETTLE_PASSWORD=%KETTLE_PASSWORD%" "-DKETTLE_PLUGIN_PACKAGES=%KETTLE_PLUGIN_PACKAGES%" "-DKETTLE_LOG_SIZE_LIMIT=%KETTLE_LOG_SIZE_LIMIT%"
Ugly, but that's Java under Windows for you. Works quite reliably now though.
Are you using the JTDS driver? Try that combined with the ntlmauth.dll - that works great for us when running PDI on Windows Server 2003 connecting to various remote sqlserver databases.
We place the DLL in this folder:
libswt\win64
I've had the same issue while using JDBC 1.2.2 with MSSQL 2008. It turns out that there is a bug in the driver, making it randomly crash if you initialize it with more than one connection.
If we used only one initial connection to the DB this error never presented itself.
The issue is fixed in a later versions of JDBC. We currently use 1.3.0 and I/O Error: SSO Failed: SSPI Not Initialized never comes up.

Resources