0

I am trying to connect to my companies Microsoft sql via my groovy code. Using this code:

String conn= "jdbc:sqlserver://;servername="+url+";databaseName=central;user=***qa***;password=***mypassword***;"
    def sqlConnection = Sql.newInstance(conn,username,password,"com.microsoft.sqlserver.jdbc.SQLServerDriver")

This results with the error:

mgroovy.lang.MissingPropertyException: No such property: connection for class: sqlKeyWords.checking[0;39m [31m at sqlKeyWords.checking.connectDB(checking.groovy:60)[0;39m [31m at sqlKeyWords.checking.invokeMethod(checking.groovy)[0;39m [31m at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)[0;39m [31m at CreateOrg.run(CreateOrg:47)[0;39m [31m at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)[0;39m [31m at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)[0;39m [31m at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:331)[0;39m [31m at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:322)[0;39m [31m at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:301)[0;39m [31m at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:293)[0;39m [31m at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:227)[0;39m [31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)[0;39m [31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)[0;39m [31m at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)[0;39m [31m at TempTestCase1555589132729.run(TempTestCase1555589132729.groovy:21)

This error is not so descriptive, therefore here is an error that I found in the debug:

The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption

I later tried this from http://docs.groovy-lang.org/latest/html/api/groovy/sql/Sql.html:

def db = [url:'jdbc:sqlserver:'+url+':central', user:username, password:password, driver:'com.microsoft.sqlserver.jdbc.SQLServerDriver']
def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)

and this resulted in:

No suitable driver found for jdbc:sqlserver:aaa-sql-qa.database.windows.bbb:dbName

I saw many answers, most of them say to play with the server's firewall, but I am able to connect to the DB via my python code or via the SSMS. Also, I don't have the ability to play with the firewall. I saw to use jTDS in this answer, but I was unable to proceed there with other issues (of course it also didn't connect)

Tomer
  • 531
  • 7
  • 19

2 Answers2

1

http://docs.groovy-lang.org/latest/html/api/groovy/sql/Sql.html

The conn variable is a simple string, so infact you are not sending the url when initializing the newInstance. Instead you send the whole string. try sending just the url.

  • Hi Dov. Thanks on your quick response! In the documentation you sent me the function dictates: Sql.newInstance(db.url, db.user, db.password, db.driver) and in the example the db.url is 'jdbc:hsqldb:mem:testDB'. So I tried String conn1= "jdbc:sqlserver:"+url+":" and it still didnt work... Also, What is the mem representing? – Tomer Apr 18 '19 at 18:45
  • 1
    @Tiner Please read the [documentation of your driver](https://learn.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=sql-server-2017) for the syntax of the JDBC url, everything after `jdbc::` is driver specific. – Mark Rotteveel Apr 19 '19 at 06:22
0

I don't know why but when running debug on the line where I connect to debug gave me this error. This occurred to me in automation tool Katalon (which uses groovy)

(Of course b/c it was not working I was trying to use debug exactly there)

Tomer
  • 531
  • 7
  • 19