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;";
aCon.Open();
queryStringSource = s;
aCmd = ADO.CreateCommand();
aCmd.ActiveConnection = aCon;
aCmd.CommandType = adCmdText;
aCmd.CommandText = queryStringSource;
aCmd.CommandTimeout = 300;
aRecSet = aCmd.Execute();
aCon.Close();
}
Hi,
Does WshShell.Run() help?
AlexKaras wrote:
Hi,
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.