-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Error trying to script using the Sql Server 2019 SMO object model #11860
Comments
A couple of general points:
The GAC applies to the .NET Framework (FullClr), and I generally wouldn't expect assemblies located there to be loadable from .NET Core (PowerShell Core) - unless they were explicitly compiled for cross-.NET-edition compatibility (against a .NET Standard version). What is the exact problem you're experiencing, and what do you expect to happen? |
The error on that line prevents scripting of SQL Server objects in the rest of the script. The script functions fine in Powershell 5, but not at all in Powershell 7. I appreciate that line is now deprecated, but I don't know how to rework it to make it compatible with Powershell 7--I'm lifting standard SQL Server scripting routines without familiarity with Powershell. Thanks. As for as Assembly.LoadString(), that's not a functional substitute here--gives this error:
|
fyi, here's a fuller excerpt of the code.
|
The method name is Both your outputs represent successful loading of the assembly per se, not errors - though as stated, I wouldn't expect the version in the GAC to necessarily work in PowerShell Core, but I have no personal experience. This blog post suggests that you'll have to install this NuGet package in PowerShell Core. Generally, please note that this repository isn't for general support questions, only for reproducible problems with PowerShell Core itself (/cc @SteveL-MSFT). See this comment for guidance. |
Thanks, that appears to be the right direction to resolve this, but installation still fails with this error:
Though not a bug, this is a backwards incompatibility with what I'd guess would be a big use case of Powershell: Sql Server admin. |
This seems to be relevant: |
Directions there (to use "a non-vanilla PS" with the "package manager"), still leave me a dependency loop, but at least I have another place to post about this.....
|
@techvslife, yes, that dependency-loop issue sounds annoying. A - cumbersome and possibly impractical - workaround is to download and extract the NuGet package manually. Looking at the broader picture, a re-architected PowerShellGet module (v3) that no longe depends on the PackageManagement (OneGet) module is being worked on: PowerShell/PowerShell-RFC#237 Now that we know that the solution lies elsewhere, please consider closing this issue. |
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
I'm grateful for your help, and I realize I'll have to get help elsewhere (note: though "msftbot" closed this, the issue is unresolved). |
According to the https://www.nuget.org/packages/Microsoft.SqlServer.SqlManagementObjects,
|
Thank you--unfortunately that fails for me, with this error: |
--Let me try it another way. |
How would you recommend installing the extracted package? |
To be clear: I meant avoiding
You need to place the relevant DLLs somewhere where your scripts can load them with Locating the relevant DLL's inside the extracted package can itself be a challenge - see #6724 As far as I know, there is no established location for where to place helper assemblies globally, aside from bundling them with a module. The alternative is therefore to package the DLLs as a PowerShell module and place them in a directory listed in |
I got pretty far, despite the dependency bug in the powershell package manager with respect to nuget packages. But basically this is unresolved, and the SMO code won't work in Powershell 7.
That's after the last line of this code:
Interestingly, the following code works perfectly fine--so I think MS did NOT port the entire server-side SMO code to .net core, or there is a bug in the attempt. Or maybe it's an issue with the buggy powershell install of nuget packages. Have no idea.
|
Thank you for your help--I did make progress, but not there yet. |
If it is a version issue (which it may not be), there are 22 (!) copies of the file Microsoft.Data.SqlClient.dll on my desktop, so not clear which one to use (some are identical, most are not). The one I'm using (to which $sqldll_path points) is at: But fwiw, these are the 22 copies:
|
This might be a bug, but I thought I was using the latest version (that should in theory have fixed it). |
Thank you for your advice -- I finally did get it working. There is a bug (a bug as far as using it in net.core) that's still uncorrected -- at least until v2 preview of microsoft.data.sqlclient. I had to use this beta version:
|
Steps to reproduce
Expected behavior
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: