Forum Discussion

TCqauser's avatar
Occasional Contributor
5 years ago

How to run a .sql file in sqlcmd mode in Javascript via TestComplete

I have a JavaScript file where I connect to the database and have to run a .sql file in order to create lots of tables etc.


I have managed to read the file, but when I execute it, it fails. The reason is that the .sql file has to be run in sqlcmd mode in order to execute.


Now I am stuck how to enable sqlcmd mode in my JavaScript file, in order to run it in TC.

Would be thankful for any assist and help.


Here comes my Javascript file:



function ExecuteScript()

var s = aqFile.ReadWholeTextFile("C:\\Database\\SQLQuery.sql", aqFile.ctUTF8);


var server = "xx.xx.xx.xx";
var dbmaster = "master";


aCon = ADO.CreateConnection();
aCon.ConnectionString = "Driver={SQL Server};Server=" + server + "; Database=" + dbmaster + ";Trusted_Connection=yes;";


queryStringSource = s;


aCmd = ADO.CreateCommand();
aCmd.ActiveConnection = aCon;
aCmd.CommandType = adCmdText;
aCmd.CommandText = queryStringSource;
aCmd.CommandTimeout = 300;
aRecSet = aCmd.Execute();



  • Hi,


    Does WshShell.Run() help?


  • AlexKaras wrote:



    Does WshShell.Run() help?


    I was just going to suggest that.  This is how I've done SQLCMD in the past.  I've created a command line routine that uses WshShell.Run that executes the SQLCMD command line to run the file.

8 Replies

  • BenoitB's avatar
    Community Hero

    Not sure to understand, your question is about how to make these ?


    SET GLOBAL sql_mode = 'modes';
    SET SESSION sql_mode = 'modes';


    BTW dont forget about checking connection state (connection.State) and post-Execute errors checking (connection.errors.count) .