Forum Discussion

Xour's avatar
Xour
Occasional Contributor
8 years ago

[Solved] [JDBC] Cannot connect to a MS SQL database

Hello. I'm having issues connecting to a MS SQL database with JDBC. I went to the JDBC drivers page and saw that there isn't a download link for MS SQL driver. So I went to the Microsoft website and downloaded the Microsoft JDBC Drivers 6.0, 4.2, 4.1, and 4.0 for SQL Server.

 

I extracted the file and added both sqljdbc.jar and sqljdbc4.jar (individually) but whenever I try to test the connection I get the following error message:

 

com.eviware.soapui.support.SoapUIException: Failed to init connection for driver [com.microsoft.sqlserver.jdbc.SQLServerDriver], connectionString [jdbc:microsoft:sqlserver://HOSTNAME\SQLExpress:3306;databaseName=MYDB;user=USER&password=PASS]

 

I checked the SoapUI log and the drivers are being loaded. For example:

 

Mon Dec 05 08:08:21 PST 2016:INFO:Adding [C:\Program Files\SoapUI-5.2.1\bin\ext\sqljdbc.jar] to extensions classpath

 

According to the error log, it seems that the driver loaded isn't the correct one:

 

Mon Dec 05 08:35:48 PST 2016:ERROR:java.sql.SQLException: No suitable driver

 

Obviously I'm doing something wrong here. Can someone help to me to understand where I'm making the mistake? If it helps, the db connection works (checked with MS SQL Server Manager) and I was able to connect to a MySQL db using SoapUI (different db though).

 

Thanks for reading and I appreciate any advice you may have!

  • PaulMS's avatar
    PaulMS
    8 years ago

    The driver is missing an r at the end (again the JDBC Driver List page is wrong) and you don't need MSSQL(MicrosoftDriver)/ at the start.
    Try
    com.microsoft.sqlserver.jdbc.SQLServerDriver

    Also copy sqljdbc4.jar to C:\Program Files\SmartBear\SoapUI-5.2.1\bin\ext

  • divergentor's avatar
    divergentor
    Occasional Contributor

    Hello, nkpalli.

    Try to revert slash in your connection string.

     

    Your connection string
    jdbc:sqlserver://databaseserver/instance;databaseName=test;integratedSecurity=true

     

    Should be
    jdbc:sqlserver://databaseserver\instance;databaseName=test;integratedSecurity=true

     

    And second point, maybe it doesn't work without login and password?

    • SuperSingh's avatar
      SuperSingh
      Contributor

      I have followed the exact steps, but am not able to get the connection to JDBC.

       

      (Note that DB is on a remote machine)

       

      I am working on Soap UI Open Source.

       

      Here is the data I provided

       

      SQL Driver : com.microsoft.sqlserver.jdbc.SQLServerDriver

      Connection String: jdbc:sqlserver://Servername\name:port;databaseName=dbname;username=username;password=password

      (I tried by removing port number also)

       

      sqljdbc_auth.dll stored in Bin folder of SoapUI

      sqljdbc4.jar stored in ext folder of SoapUI

       

      Running this gives the following error :

       

      Can't get the Connection for specified properties; com.microsoft.sqlserver.jdbc.SQLServerException: The server version is not supported. The target server must be SQL Server 2000 or later.

       

      Appreciate any help !

       

      Thanks

      Predator

      • PaulMS's avatar
        PaulMS
        Super Contributor

        What SQL version number can you see if you connect to the database server in SQL server management?

        Did you download the latest Microsoft JDBC Driver 6.0 for SQL Server?

         

  • divergentor's avatar
    divergentor
    Occasional Contributor

    Thank you guys for help. 

    Now everything is ok and I can work with my local DB.

     

    If you don't mind I keep my steps here, maybe it can help somebody.

     

     

    If you are using local DB

     

    1) Put sqljdbc4.jar file to the directory C:\Program Files\SmartBear\SoapUI-5.2.1\lib. Do not use version sqljdbc41.jar and sqljdbc42.jar. (They do not work for some reason for me.)
    2) Turn on SQL server browser
    3) Go to the SQL server configuration/ choose SQL server network configuration and set TCP/IP enable
    4) Restart the SQL server
    5) In the test case create a JDBC step with properties
    Driver
    com.microsoft.sqlserver.jdbc.SQLServerDriver
    Connection Sting (example)
    jdbc:sqlserver://localhost\sqlexpress;databaseName=DataDB;user=admin;password=admin

     

    • nkpalli's avatar
      nkpalli
      Contributor

      Trying to connect to  SQL server Database on remote server using SOAPUI 5.2.1 version and running into issues :  

       pre-requisite :  i have downloaded sqljdbc4.jar file and put that in local  directory C:\Program Files\SmartBear\SoapUI-5.2.1\lib

       

      1) created a JDBC step with properties

      Driver : com.microsoft.sqlserver.jdbc.SQLServerDriver

      Connection Sting: jdbc:sqlserver://databaseserver/instance;databaseName=test;integratedSecurity=true

       

      here below is error message: 

      com.eviware.soapui.support.SoapUIException: Failed to init connection for driver [com.microsoft.sqlserver.jdbc.SQLServerDriver], connectionString [jdbc:sqlserver://databaseserver/instance;databaseName=test;integratedSecurity=true]

      2)Turn on SQL server browser
      4) Go to the SQL server configuration/ choose SQL server network configuration and set TCP/IP enable
      5) Restart the SQL server
      still cannot connect . Any suggestions ? 


  • divergentor's avatar
    divergentor
    Occasional Contributor

    Hello.

     

    I have the same problem and I still could not solve it. Maybe you can help me.

     

    1) I have downloaded Microsoft JDBC Driver 6.0 for SQL Server.

    2) From this folder I took file sqljdbc.jar and copy paste it to the folders 

    C:\Program Files\SmartBear\SoapUI-5.2.1\bin\ext

    and

    C:\Program Files\SmartBear\SoapUI-5.2.1\lib

    3) I configured my JDBC step as

    Driver

    MSSQL(MicrosoftDriver)/com.microsoft.sqlserver.jdbc.SQLServerDrive

     

    Connection String

    jdbc:sqlserver://localhost\sqlexpress;databaseName=DataVision;user=admin;password=admin

     

    After check connection I see the error as you

     

    com.eviware.soapui.support.SoapUIException: Failed to init connection for driver [MSSQL(MicrosoftDriver)/com.microsoft.sqlserver.jdbc.SQLServerDrive], connectionString [jdbc:sqlserver://localhost\sqlexpress;databaseName=DataVision;user=admin;password=admin]

     

     

    this is scr with my example

    Could you please push me to the right may. 

    Thx in advance.

    • PaulMS's avatar
      PaulMS
      Super Contributor

      The driver is missing an r at the end (again the JDBC Driver List page is wrong) and you don't need MSSQL(MicrosoftDriver)/ at the start.
      Try
      com.microsoft.sqlserver.jdbc.SQLServerDriver

      Also copy sqljdbc4.jar to C:\Program Files\SmartBear\SoapUI-5.2.1\bin\ext

    • Xour's avatar
      Xour
      Occasional Contributor

      I'll try for sure.

       

      This is the current configuration for my JDBC step:

       

      - Driver: com.microsoft.sqlserver.jdbc.SQLServerDriver

      - Connection String: jdbc:sqlserver://HOSTNAME\sqlexpress;databaseName=MYDB;username=USER;password=PASS

      - Driver File: C:\Program Files\SoapUI-5.2.1\bin\ext\sqljdbc4.jar

       

      And that's it!

       

      Let me know if it works

      • wujianyy's avatar
        wujianyy
        Contributor

        Another solution is to use groovy script.  You can use Windows Authentication to access sql server database. 

         

        Notice of extra jar and dll: 

        1 The files of JDBC driver(MSSQL(MicrosoftDriver)/com.microsoft.sqlserver.jdbc.SQLServerDrive) isn't distributed with SoapUI Free version. .jar and .dll must be copied into the folder of Soapui folder.

        - sqljdbc_auth.dll must be copied to ..\SoapUI-5.2.1\bin\
        - sqljdbc42.jar must be copied to ..\SoapUI-5.2.1\lib\.

        2 JDBC driver link https://www.soapui.org/jdbc/reference/jdbc-drivers.html

        3 sqljdbc42.jar can be used in jdk 1.8

  • PaulMS's avatar
    PaulMS
    Super Contributor

    I had the same problem because the connection string example on the JDBC Driver List page is wrong.

     

    jdbc:microsoft:sqlserver://HOSTNAME\SQLExpress:3306;databaseName=MYDB;user=USER&password=PASS

    should be 

    jdbc:sqlserver://HOSTNAME\SQLExpress:3306;databaseName=MYDB;user=USER;password=PASS

    • Xour's avatar
      Xour
      Occasional Contributor

      I realized that yesterday morning, forgot to update the thread!

       

      Took me quite a while to figure it out haha

       

      Thanks!