-
-
Notifications
You must be signed in to change notification settings - Fork 821
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
Invoke-DbaQuery throws error "cannot be changed or read after a connection string has been set" #4946
Comments
I see why the error is happening, but I cannot repro on my end just yet. This error is most likely happens because Invoke-DbaQuery now passes -ApplicationIntent parameter every time and connection string gets adjusted on line 364: It was not happening before since ApplicationIntent was added to Invoke-DbaQuery quite recently. |
Okay, updated my repo to recent version, can 100% repro now on both windows and sql auth. |
@potatoqualitee PR is ready, was able to fix it without too much fuss, but there are still some concerns about other two parameters that might not work properly with SqlCredentials |
fantastic thank you so much i'll reopen this until the other two params are checked |
this should be fixed 💯 |
I am facing this error with Write-DbaDbTableData function.
|
Thank you for the report @ajaydwivedi-angelone. What settings did you set for the original $Distributorobject? @andreasjordan would you be able to take a look? |
I'll take a look. |
I can not repro the problem at the moment. @ajaydwivedi-angelone can you please run the command with |
Want to highlight fact that my scenario involves cross domain servers. The remove SQL Server can only be connected using IP not name as name does not resolve. Below is output with verbose & debug -
|
Thanks for the details. To dig deeper we need to introduce a new step to first change the connection context and test the resulting connection before using Write-DbaDbTableData. So please run this:
If this works, you could try to use this in the next command:
You could also try to use |
Executed
Below is output -
I removed & recreated variable $Distributor like below -
Getting below error -
|
The last one is interesting: It looks like |
I have added all Servers with IP & So I scan $DistributorIP value across Registered Servers and create Server Object using
|
I would like to eleminate the use of registered servers. Can you connect to the instance without using |
Invoke-DbaQuery may not force a change of the connection context. Write-DbaDbTableData forces a non pooled connection and sets a database context. And that is not working properly. In any case we can only try to find a workaround as the issue is probably related on how the SMO is handling the connections. We can't do anything about that. So I would like to see if you can open a non pooled connection to the target database with connect-dbainstance and then use that connection with Write-DbaDbTableData. |
I am closing this issue now. If any of the problems discussed here are reproducible with the current version of dbatools, please open a new issue. |
Before submitting a bug report:
powershell -NoProfile
)Steps to Reproduce
Expected Behavior
10 rows returned
Actual Behavior
Environmental data
PowerShell:
Machine Two
This happens on 0.9.740 on both Windows PowerShell and PowerShell Core.
The text was updated successfully, but these errors were encountered: