Ask a Question

unable to connect to SQL server database, script assertion window

nkpalli
Contributor

unable to connect to SQL server database, script assertion window

While trying to work on API request i have added a script assertion to connect to SQL server database instance to query a table and i get this error .  Can you let me know why the script is failing with unexpected char '\' . can we connect to Databasename\Instance name?

 

 

Here below is snippet of script assertion added to connect to my SQL server database instance

 

import java.sql.*;
import groovy.sql.Sql

class Example {
   static void main(String[] args)
{
           
           
def sql =Sql.newInstance("jdbc:sqlserver://LRO-QA-SQL\QADB3;Database=DBname;integratedSecurity=true","com.microsoft.sqlserver.jdbc.SQLServerDriver")
}
def row = sql.firstRow("select top 1 from community")

 

Here below is error :

 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 11: unexpected char: '\' @ line 11, column 54. e("jdbc:sqlserver://LRO-QA-SQL\QADB3;Dat ^ org.codehaus.groovy.syntax.SyntaxException: unexpected char: '\' @ line 11, column 54. at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:135) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:108) at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236) at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:162) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:912) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:574) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:550) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:527) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:613) at groovy.lang.GroovyShell.parse(GroovyShell.java:625) at groovy.lang.GroovyShell.parse(GroovyShell.java:652) at groovy.lang.GroovyShell.parse(GroovyShell.java:643) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:136) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:87) at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141) at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: Script1.groovy:11:54: unexpected char: '\' at org.codehaus.groovy.antlr.parser.GroovyLexer.mESC(GroovyLexer.java:2180) at org.codehaus.groovy.antlr.parser.GroovyLexer.mSTRING_CTOR_END(GroovyLexer.java:2226) at org.codehaus.groovy.antlr.parser.GroovyLexer.mSTRING_LITERAL(GroovyLexer.java:1985) at org.codehaus.groovy.antlr.parser.GroovyLexer.nextToken(GroovyLexer.java:468) at org.codehaus.groovy.antlr.parser.GroovyLexer$1.nextToken(GroovyLexer.java:258) at groovyjarjarantlr.TokenBuffer.fill(TokenBuffer.java:69) at groovyjarjarantlr.TokenBuffer.LA(TokenBuffer.java:80) at groovyjarjarantlr.LLkParser.LA(LLkParser.java:52) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.pathExpression(GroovyRecognizer.java:11604) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.postfixExpression(GroovyRecognizer.java:13332) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.unaryExpressionNotPlusMinus(GroovyRecognizer.java:13301) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.powerExpressionNotPlusMinus(GroovyRecognizer.java:13005) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.multiplicativeExpression(GroovyRecognizer.java:12937) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.additiveExpression(GroovyRecognizer.java:12607) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.shiftExpression(GroovyRecognizer.java:9824) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.relationalExpression(GroovyRecognizer.java:12512) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.equalityExpression(GroovyRecognizer.java:12436) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.regexExpression(GroovyRecognizer.java:12384) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.andExpression(GroovyRecognizer.java:12352) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.exclusiveOrExpression(GroovyRecognizer.java:12320) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.inclusiveOrExpression(GroovyRecognizer.java:12288) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.logicalAndExpression(GroovyRecognizer.java:12256) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.logicalOrExpression(GroovyRecognizer.java:12224) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.conditionalExpression(GroovyRecognizer.java:4850) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.assignmentExpression(GroovyRecognizer.java:8027) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.expression(GroovyRecognizer.java:10001) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.expressionStatementNoCheck(GroovyRecognizer.java:8353) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.varInitializer(GroovyRecognizer.java:2682) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.variableDeclarator(GroovyRecognizer.java:7928) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.listOfVariables(GroovyRecognizer.java:7882) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.variableDefinitions(GroovyRecognizer.java:2278) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.declaration(GroovyRecognizer.java:2140) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.statement(GroovyRecognizer.java:1208) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.blockBody(GroovyRecognizer.java:1495) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.openBlock(GroovyRecognizer.java:8315) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.variableDefinitions(GroovyRecognizer.java:2364) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.declaration(GroovyRecognizer.java:2140) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.classField(GroovyRecognizer.java:5945) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.classBlock(GroovyRecognizer.java:5245) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.classDefinition(GroovyRecognizer.java:1942) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.typeDefinitionInternal(GroovyRecognizer.java:1822) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.statement(GroovyRecognizer.java:1305) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.compilationUnit(GroovyRecognizer.java:757) at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:131) ... 20 more 1 error

 

 

 

2 REPLIES 2
nkpalli
Contributor

The JDBC request call ran successful but script assertion fails when trying to do Inline SQL server connect

New2API
Frequent Contributor

Hi, looks like in your connection string you have a '\'. (I have highlighted in red)

 

def sql =Sql.newInstance("jdbc:sqlserver://LRO-QA-SQL\QADB3;Database=DBname;integratedSecurity=true","com.microsoft.sqlserver.jdbc.SQLServerDriver")
}
def row = sql.firstRow("select top 1 from community")

 

 

see if you can use SQL server name without any instance or try using a escape character as shown below.

 

def sql =Sql.newInstance("jdbc:sqlserver://LRO-QA-SQL\\QADB3;Database=DBname;integratedSecurity=true","com.microsoft.sqlserver.jdbc.SQLServerDriver")
}
def row = sql.firstRow("select top 1 from community")

 

Regards!

cancel
Showing results for 
Search instead for 
Did you mean: