-
Notifications
You must be signed in to change notification settings - Fork 21
Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer sometimes empty when used remotly #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Agreed, I've experienced these issues for years, over several versions of SMO. It's so unpredictable, our internal command has to try locally then remotely, as you know. I'd love to see a solution. |
I think I found a solution. After uninstalling SQL Server 2019, the corresponding WMI namespace "ComputerManagement15" is still present on the computer ( It looks like the remote WMI connection always "connects" to the highest available namespace. After removing the namespace with So the WMI connection should not only connect to the highest namespace, but also see if this namespace "is filled". And if not, continue with the next smaller namespace. |
@Matteo-T is the leftover WMI namespace "by design" after uninstalling SQL? |
One additional information: If I connect via WinRM and run the code locally on the target (with |
Not sure exactly how this works, but I recall version mismatches being problematic. It's already a bit slow so I imagine that's the reason each available namespace isn't interrogated. Maybe multithreading can help? |
@shueybubbles - setup in this area had not changes in probably a decade, so I'm not surprised if there are bugs. @potatoqualitee - this is NOT the same issue that (1) is still affecting SQLPS (2) it stopped affecting SQLServer a long time ago. This seems to be just the WMI provider in SQL Server setup that is not unregistering itself properly. I'd have to follow up with the SQL Setup folks and see what we can do about it, at least in the next SQL version. @andreasjordan - your theory seems reasonable. Considering that, at best this will be addressed in SQL vNext, we may still need/want to put logic into SMO to workaround this possible problem. |
As an aside, in the early version of SQLServer per PS6/7, the WMI class in SMO was totally unavailable so I moved away from that stuff altogether. I traded the WMI stuff with remote registry access... which, at least, was available. I also recall some talks around "what about WMI on non-Windows?" but I think the thread kind of died a while back... |
@andreasjordan - FWIW, I am not able to repro the original problem you reported both then I use the v150 version of SMO that comes with the SQLServer module and when I created a C# application that uses the latest SMO package (161.47008.0) available on nuget.org. Perhaps, you should have a word with the owners of DBATools :-) or narrow it down to a non-dbatools specific problem (I agree that, in principle, SQL 2019 setup should remove the class/namespace when it is uninstalled, but that's a different story). |
LOL burrrn 🔥 |
Thanks for trying to repro. In the next free time slot, I will get the nuget package and test. |
The key to the repro is a reboot after uninstalling SQL 2019 - at least for me. So, it would appear that SQL 2019 uninstall is "doing something" with the WMI namespace/classes, but not something that is fully committed until after a reboot happens (maybe a missing forceupdate somewhere?) |
Ok, I now rebooted after removing SQL Server 2019 - but the namespace is still there. Here my code for documentation:
Next step is to use last version of SMO from nuget. Will keep you updated. |
@andreasjordan - no need for that. It's just a bug in SQL. I have several repros and I've started a conversation with some folks here. As I said, we need to get creative and put some workaround in place in SMO or at least make sure that we provide a dcent way to "complete the uninstall" (the one you have may be "good enough" - I just don't know enough about about WMI and mofcomp to tell if there's a better way to go about it) |
@shueybubbles - one way to go about it could be to expose an overload of the ctor that takes the namespace (or the version) and just uses that instead of the heuristic we have today. That would address @potatoqualitee's complain about performance (if the right namespace is at the very end of the list, I can see taking several seconds or minutes for all the requests to timeout). |
But we don't know the namespace. And the "filled" namespace has information about all the instances regardless of their version. |
After all, I installed a version 2016 instance:
So it looks like this to me: Namespaces for a version without an installed instance are completely empty. Namespaces for a version with an installed instance contain information about all installed instances on the computer. So we need to get the higherst filled namespace. |
That is how we get the services:
|
It looks like this is where all the possible namespaces are iterated to get a connection: sqlmanagementobjects/src/Microsoft/SqlServer/Management/Smo.Wmi/ManagedComputer.cs Lines 329 to 346 in 9809360
And the namespace15 (in my example) is there, so the connection is successful. It is just empty - which is not tested. Can you add a "test for emptyness" after line 337 and if the namespace is empty, not return but continue? That would then test with namespace14 and find the higherst filled namespace. |
FWIW, I have a fix ready (in SQL vNext) to make this right. |
Wow, awesome! 💯 💯 💯 💯 |
PR with the fix sent out (in our internal fork). |
Nice! |
…lly uninstalling the SQL W... Workaround for WMI issue caused by SQL Setup not fully uninstalling the SQL WMI Provider (SQL 2019 and earlier) The issue is described on [Github](#83), but basically it's like this: - SQL Setup does not uninstall completely the SQL WMI Provider - SMO has logic (heuristic) to figure out the proper WMI Namespace to connect to - The left-over namespace (of the uninstalled SQL) is still there, but not functional - The current heuristic would just use it - However, when WMI queries happen things fall apart because there is no code to backup that namespace The experience, at least when the WMI object is used from PowerShell is just a bunch of empty fields, which are super confusing. The fix is just about using a slightly different (and hopefully equally lightweight and reliable) WMI query: if that works, odds are that we hit the right/valid namespace. Out of scope: - Trying to make the whole probing logic (currently on 8 namespaces) parallel (the code in the WMI classes is not very thread-safe from what I see, so the change to do stuff in parallel would require a little more work... and also a bit of profiling to confirm it's really needed)
I use the SMO version included in dbatools, GetType().Assembly shows version v4.0.30319.
I use this code from a management server with dbatools to a access a server with the SQL Server instance:
What I did:
It looks like the connection is targeted to some kind of left over version 2019 endpoint which is not able to get me the information.
As soon as I install a version 2019 instance again, the information is back there.
Any ideas?
The text was updated successfully, but these errors were encountered: