Forum Discussion

niyaz's avatar
niyaz
Occasional Contributor
9 years ago

Database connection to SQl Server 2008 R2

Hi All,

       I have imported sqljdbc4.2 jars in Soapui lib directory and using groovy want to connect to SQL Server 2008 R2 Edition with windows authentication.Please find the below code for and correct if I am wrong in my assumption.

 

import groovy.sql.Sql

try{

def dbURL = "jdbc:sqlserver:/servername:1433/databasename"
def dbUsername = "username"
def dbPassword = "password"
def dbDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
def sql = Sql.newInstance(dbURL,dbUsername,dbPassword,dbDriver)

log.info "Connected to database successfully"

}catch(Exception e){
log.info "some db error"
log.info e.getMessage()
}

 

For the above code I am getting below error :

  • Mon Aug 17 11:53:48 IST 2015:INFO:some db error
  • Mon Aug 17 11:53:48 IST 2015:INFO:No suitable driver found for jdbc:microsoft:sqlserver:/server name:1433/database name

It is going to catch block and executing the statements.

 

Please help if missing any workaround for it.

 

Regards,

Niyaz

9 Replies

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi Niyaz,

     

    Just a quick note and sorry if you have already tried this, but where you say that you have added the SQL Server jar to the SoapUI lib folder, do you mean as in <SoapUI Home>/lib folder? As this might work, but the normal way to add external libraries is actually to add them to <SoapUI Home>/bin/ext (you will see a readme file in here saying this). If the jar file is added to the bin/ext folder then you can check to see an info message in the SoapUI log saying whether the jar file has actually been added, if there is none it hasn't.

     

    Possibly the lib folder is equivalent, maybe a different classpath, but I just wanted to check in case it helps.

     

    Cheers,

    Rupert

    • niyaz's avatar
      niyaz
      Occasional Contributor

      Hi Rupert,

         I have added jars into /bin/ext directory too. Now, I am getting login failed for user username while connecting to the database.The authentication mode in SQL Server is mixed mode only.Please help me in resolving this issue.Waiting for your reply.

       

      Regards,

      Niyaz

       

      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        Hi Niyaz,

         

        Ok good, it sounds like you have fixed the class load issue, which is something.

         

        Unfortunately, my experience of SQL Server is very old and I don't have a windows machine to install it on.

         

        Can any Windows/SQL Server users help Niyaz get the authentication sorted out please?

         

        Sorry not to be of more help,

         

        Cheers,

        Rup