Replies: 1 comment
-
Hello Found the solution a database was in transaction with status online |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
Below error is returned when we launched get-dbadatabase -sqlinstance TESTSQL
WARNING: [11:51:48][Invoke-QueryRawDatabases] Failure | You cannot call a method on a null-valued expression.
We have a look on function and try to execute each query :
function Invoke-QueryRawDatabases {
try {
if ($server.isAzure) {
$dbquery = "SELECT db.name, db.state, dp.name AS [Owner] FROM sys.databases AS db LEFT JOIN sys.database_principals AS dp ON dp.sid = db.owner_sid"
$server.ConnectionContext.ExecuteWithResults($dbquery).Tables
} elseif ($server.VersionMajor -gt 8) {
$server.Query("
SELECT name,
CASE DATABASEPROPERTYEX(name,'status')
WHEN 'ONLINE' THEN 0
WHEN 'RESTORING' THEN 1
WHEN 'RECOVERING' THEN 2
WHEN 'SUSPECT' THEN 4
WHEN 'EMERGENCY' THEN 5
WHEN 'OFFLINE' THEN 6
END AS state,
SUSER_SNAME(sid) AS [Owner]
FROM master.dbo.sysdatabases
")
} else {
$server.Query("SELECT name, state, SUSER_SNAME(owner_sid) AS [Owner] FROM sys.databases")
}
} catch {
Stop-Function -Message "Failure" -ErrorRecord $_
}
}
Thank you
Regards
Beta Was this translation helpful? Give feedback.
All reactions