If you are writing TestComplete automation script and require to find logical file name of the SQL database from the DB backup file before restoring the database then check the below function which can provide this information.
The javascript function retrieves the logical file name of the SQL database from DB backup file.

Make the call to “getDBLogicalName” function –
 

function test()
{
  var logicalname = []
  var dbserver = "127.0.0.1"; //server IP where SQL server is installed
  var bkupdbname = "C:\\data\\Demodb.bak";  //SQL DB backup path with the file name 
  logicalname = getDBLogicalName.getDBLogicalName(dbserver,bkupdbname)
}

 

function getDBLogicalName(dbserver,bkupdbname)
{
	var aCon 
	var logicalnamedata = [] 
	var server, dbSourceFile, queryStringSource;
  
	server = dbserver; 
	dbmaster = "master";
	dbSourceFile = bkupdbname;
	
	aCon = ADO.CreateConnection();
	aCon.ConnectionString = "Driver={SQL Server};Server=" + server + "; Database=" + dbmaster + ";Trusted_Connection=yes;";
	aCon.Open();
		
	queryStringSource =  "EXEC('RESTORE FILELISTONLY FROM DISK=''" +dbSourceFile+ "''');"
	
	aCmd = ADO.CreateCommand();
	aCmd.ActiveConnection = aCon; // Connection
	aCmd.CommandType = adCmdText; // Command type
	aCmd.CommandText = queryStringSource; 
	aCmd.CommandTimeout = 300; 
	aRecSet = aCmd.Execute();
	if(aRecSet.EOF)
	{
		Log.Message("logical name not found")
	}
	else
	{
		logicalnamedata[0] = aRecSet.Fields.Item(0).Value
		aRecSet.MoveNext();
		logicalnamedata[1] = aRecSet.Fields.Item(0).Value
	}
	return logicalnamedata 
}