The below code explains how to restore SQL database using javascript in TestComplete.

 server = “10.22.11.100” //DB server IP or name
 database = “TestDB” //DB name to be restored
 dbSourceFile = “C:\\ayz\\db.bak” // path where the DB backup is placed
 dbmaster = “master”;

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

 queryStringSource = “RESTORE DATABASE ” + database + ” FROM DISK = N'” + dbSourceFile + “‘ WITH MOVE N’xyz_data’ TO N’C:\\Program Files\\Microsoft SQL Server\\MSSQL13.MSSQLSERVER\\MSSQL\\DATA\\XYZ_data.MDF’, MOVE N’xyz_Log’ TO N’C:\\Program Files\\Microsoft SQL Server\\MSSQL13.MSSQLSERVER\\MSSQL\\DATA\\XYZ_Log.LDF’;”;

 aCmd = ADO.CreateCommand();
 aCmd.ActiveConnection = aCon; // Connection
 aCmd.CommandType = adCmdText; // Command type
 aCmd.CommandText = queryStringSource; // Table name
 aCmd.CommandTimeout = 300; // Table name
 aRecSet = aCmd.Execute();
 aCon.Close();

Note: ‘xyz_data’ and ‘xyz_Log’ are logical names of your database. Replace the names as per your DB backup.