-
Notifications
You must be signed in to change notification settings - Fork 225
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
xSQLServerAlwaysOnAvailabilityGroup: SqlServer Module v21.0.17099 breaks the resource #649
Comments
Hmm... Did we finally get into a problem with using LoadWithPartial in the helper function Connect-SQL (I have been afraid of that). Issue #520. 🤔 @randomnote1 Have you seen this error? |
I haven't seen that yet. The only time I've seen it is when I messed up the smo stubs when running unit testing. |
I have reproduced the same problem. But it's gonna be quite a task to debug this one I think. :) |
So when I reproduced this I used SQL Server 2014. I get the same error as above.
And it is this row that fails (and throws)
But when I run this code manually and using SqlServer v21 module I get this error. When using SQLPS I don't get this error. So it seems SqlServer module is not backward compatible. That means we have to rethink the whole idea of loading SqlServer module as the preferred module unless SQL Server is, what 2017?
@Zuldan Since you are using SQL Server 2016 I have to revert the test VM and deploy SQL 2016 instead to try to reproduce the error. It seems it doesn't say the actual error (after the result above), so gonna be interesting to see what it says on a SQL Server 2016. |
Get the same error with SQL Server 2016 and SqlServer module. So I can reproduce it there too.
Manually everything works. Note that I use all helper functions, exactly as it does when it is run thru LCM.
But it is the
Guess we have to try to force load the new and old assembly in
|
Every problem is an opportunity for improvement (or so I'm told 😁 )! |
And opportunity for learning too 😄 |
Okay, I think I found it. It's wrong of us to use LoadWithPartialName as stated in issue #520. It was a problem with wrong version of the assembly was loaded with LoadWithPartialName, because the wrong assembly is present in the GAC while the SqlServer module assemblies are not. And even if the assembly would have been in the GAC, using LoadWithPartialName would have loaded the first assembly it found. That could on some target nodes be the correct assembly, and on other target nodes it could have been the wrong assembly. Instead we should just import the correct module and the necessary assemblies (and only the correct version) will load, and then the type used ([Microsoft.SqlServer.Management.Smo.Server]) will be the correct version. We still have the problem that SqlServer module is not supported on older version. I will investigate that further and see how we solve that. Maybe we need to support loading an assembly with a strong name with older SQL Server versions (2014 and below). Or we just say that for SQL Server 2016 and newer the SqlServer module is the preferred one, and on SQL Server 2014 and older, the old SQLPS is the preferred one. But If using both SQL Server 2016 and SQL Server 2014 on the same target node would mean that SQL Server 2014 would break if SqlServer module is deployed unless the helper function Import-SQLPSModule knows what version we are installing and load the correct module. For this to work, we need to have a solution that works when all version of SQL Server is installed side-by-side (2008 R2, 2012, 2014, 2016, 2017 and vNext). I will start with making this issue work, so @Zuldan can test (if possible). This will be a breaking change. |
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649).
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server. Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server. Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server. Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
@Zuldan You can find a fix for your particular issue in my working branch here; https://github.com/johlju/xSQLServer/tree/fix-issue-649. I will not PR in it yet, because I have to test a whole lot of scenarios mentioned above. It will fix your issue (tested and working in my lab). In my working branch you only need the file xSQLServerHelper.psm1, and in particular the functions In the helper function Connect-SQL, this row was change from this
To this
When not using the module SqlServer I'm got the below error from the Set-method after successfull instalation of SQL Server.
This was solved using this, to refresh the PSModulePath environment variable before loading the SQLPS module. This actually solved another issue that I seen with xSQLServerScript that I hadn't gotten around to investigate yet. 😄
|
@johlju wow thank you for making a fix so quickly. I will test this first thing Monday morning and report back. |
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
@johlju apologies for the delay it's been a crazy week. It's looks like you have found the solution. It's working for me. Thanks again for fixing this so quickly. Sending a virtual pack of beer to you! |
Let's keep this open until the fix is merged. In a week or so I'm hoping I can verify the other scenarios mentioned above, and after that I can PR in the fix. |
@Zuldan Happy to hear it's working for you! |
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
Hi, I had the same problem and using Import-SQLPSModule fixes the issue Thanks for the fix. |
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
@mdaniou Glad to hear that it solved you problem. Please report any issue you have with this fix. I haven't had the time to verify this fix so this will not be included in the 8.0.0.0 release. |
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
Hi @johlju I am new to DSC and having the same problem as above using version 8.0.0.0 I have tried to overwrite the files from your branch into my 8.0.0.0 folder. Am I missing something else to register your changes? Errors as follows: PowerShell DSC resource MSFT_xSQLServerAlwaysOnAvailabilityGroup failed to execute Set-TargetResource functionality with error message: Creating the availability group 'TestAG'. InnerException: Cannot bind parameter 'InputObject'. Cannot convert the I also notice : Information: PowerShell module SqlServer not found, trying to use older SQLPS module. Many thanks! Paul |
This is interesting. It loads the SQLPS module, and you getting this error. Can you please post the verbose log from the run when you get the error (remove any sensitive information)? it would help me to do further testing with this bug fix.
Have you downloaded the SqlServer module (together with the xSQLServer module) to the target node? Doesn't seem to be able to load the SqlServer module. |
@johlju Thankyou for the prompt response. You are a legend. My issue is resolved! I only downloaded the xSQLServer module and not the SQLServer Module. Best Regards! Paul |
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
I have tested this fix with both SQLPS and SQLServer and it seems it works. This fix works in these tested scenarios:
The problem I got above with SQL Server 2014 seems to be limited to creating Availability Groups in SQL Server 2014 using the PowerShell module SqlServer. I will open another issue to track that. So I'm feeling confident that we can merge this code. |
Submitted new issue #772 to track the problem creating Availability Groups using SqlServer PowerShell module in SQL Server 2014 SP2. |
Problem with integration test with these fixes. see issue #774. |
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
- Changes to xSQLServer - Updated appveyor.yml so that integration tests can run in AppVeyor (issue dsccommunity#774). - Changes to xSQLServerSetup - Fixed so that the integration test copies back the SQLPS module (issue dsccommunity#774).
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649). Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
- Changes to xSQLServer - Updated appveyor.yml so that integration tests can run in AppVeyor (issue dsccommunity#774). - Changes to xSQLServerSetup - Fixed so that the integration test copies back the SQLPS module (issue dsccommunity#774).
Removed the breaking change for this issue. If anyone feels it still should be a breaking change. Let me know. |
- Changes to xSQLServer - Updated appveyor.yml so that integration tests run in order and so that the SQLPS module folders are renamed to not disturb the units test, but can be renamed back by the integration tests xSQLServerSetup so that the integration tests can run successfully. (issue #774). - Changes to xSQLServerHelper - Changes to Connect-SQL and Import-SQLPSModule - Now it correctly loads the correct assemblies when SqlServer module is present (issue #649). - Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server. Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path. - Changes to xSQLServerSetup - Fixed so that the integration test renames back the SQLPS module folders if they was renamed by AppVeyor (in the appveyor.yml file). (issue #774). - Fixed so integration test does not write warnings when SQLPS module is loaded (issue #798).
I've just run into this issue as well, guessing it wasn't included in 9.0.0.0 (and you branch with the fix link doesn't work anymore) I had PSSQL module installed. I had to install SqlServer module from the PSGallery to make it work. |
Details of the scenario you tried and the problem that is occurring:
When using the Microsoft SQLServer Module v21.0.17099 (https://www.powershellgallery.com/packages/SqlServer/21.0.17099), xSQLServerAlwaysOnAvailabilityGroup errors with "Cannot bind parameter 'InputObject'. Cannot convert the "[LABSERVER01]" value of type "Microsoft.SqlServer.Management.Smo.Server**" to type "Microsoft.SqlServer.Management.Smo.Server".**"
If I just use SQLPS, xSQLServerAlwaysOnAvailabilityGroup runs perfectly and creates the AOAG groups as instructed.
The DSC configuration that is using the resource (as detailed as possible):
N/A
Version of the Operating System, SQL Server and PowerShell the DSC Target Node is running:
Windows Server 2012 R2
SQL Server 2016 SP1 CU3
PS 5.1
What module (SqlServer or SQLPS) and which version of the module the DSC Target Node is running:
SqlServer v21.0.17099
Version of the DSC module you're using, or 'dev' if you're using current dev branch:
7.1.0.0
The text was updated successfully, but these errors were encountered: