-
Suggestion
-
Resolution: Unresolved
-
None
-
1
-
9
-
Currently, the sqlcmd connects only to the default DB instance on the server. If there are other instances on the server, they will not be scanned. The solution for Windows Servers with SQL Server is as follows:
- Integrate into the C# Code an additional loop using the following command:
--> reg.exe query "HKLM\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"
This will render the list of instances on the server as follows:
HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL
INSTANCE1 REG_SZ MSSQL15.INSTANCE1
INSTANCE2 REG_SZ MSSQL15.INSTANCE2
Using the string Instance Names "INSTANCE1" and "INSTANCE2" then for each the following command can be executed (note that we prepended the connection to the localhost IP and InstanceName - this is where the Instance Names from the first command need to be injected):
sqlcmd -S 127.0.0.1\INSTANCE1 -E -Q "SELECT DB.name, SUM(CASE WHEN type = 0 THEN cast(MF.size as bigint) * 8 / 1024 ELSE 0 END) AS DataFileSizeMB, SUM(CASE WHEN type = 1 THEN cast(MF.size as bigint) * 8 / 1024 ELSE 0 END) AS LogFileSizeMB, @@servicename AS InstanceName, (SELECT TOP 1 local_tcp_port FROM sys.dm_exec_connections WHERE local_tcp_port IS NOT NULL ORDER BY last_read DESC) AS Port FROM sys.master_files MF JOIN sys.databases DB ON DB.database_id = MF.database_id GROUP BY DB.name" sqlcmd -S 127.0.0.1\INSTANCE2 -E -Q "SELECT DB.name, SUM(CASE WHEN type = 0 THEN cast(MF.size as bigint) * 8 / 1024 ELSE 0 END) AS DataFileSizeMB, SUM(CASE WHEN type = 1 THEN cast(MF.size as bigint) * 8 / 1024 ELSE 0 END) AS LogFileSizeMB, @@servicename AS InstanceName, (SELECT TOP 1 local_tcp_port FROM sys.dm_exec_connections WHERE local_tcp_port IS NOT NULL ORDER BY last_read DESC) AS Port FROM sys.master_files MF JOIN sys.databases DB ON DB.database_id = MF.database_id GROUP BY DB.name"
Adapting the pattern file and C# code will help us to scan all the DB instances.
- depends on
-
JSMAD-120 You do not have permission to view this issue