Skip to content
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

[Bug] Export-DbaCredential - -Identity doesn't filter, DAC duplication problem #5443

Closed
2 of 3 tasks
asnest opened this issue Apr 30, 2019 · 5 comments · Fixed by #5521
Closed
2 of 3 tasks

[Bug] Export-DbaCredential - -Identity doesn't filter, DAC duplication problem #5443

asnest opened this issue Apr 30, 2019 · 5 comments · Fixed by #5521
Assignees

Comments

@asnest
Copy link

asnest commented Apr 30, 2019

Before submitting a bug report:

Collect output of following command and paste below:

& {"### PowerShell version:`n$($PSVersionTable | Out-String)"; "`n### dbatools Module version:`n$(gmo dbatools -List | select name, path, version | fl -force | Out-String)"}
  • Running latest release of dbatools
  • Verified errors are not related to permissions
  • Is this bug with Copy-DbaDatabase? You can replicate it using Backup-DbaDatabase ... | Restore-DbaDatabase ...

NOTE: Copy-DbaDatabase will not work in every environment and every situation. Instead, we try to ensure Backup & Restore work in your environment.

Environmental data

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      5.1.14393.2879
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.2879
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1




### dbatools Module version:


Name    : dbatools
Path    : C:\Program Files\WindowsPowerShell\Modules\dbatools\0.9.811\dbatools.psd1
Version : 0.9.811

SQL Server:

Microsoft SQL Server 2016 (RTM-GDR) (KB4019088) - 13.0.1742.0 (X64)   Jul  5 2017 23:41:17   Copyright (c) Microsoft Corporation  Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2016 Datacenter 6.3 <X64> (Build 14393: ) 

Errors Received

<# OUTPUT of $error[0] | select * #>

Steps to Reproduce

/*
    Any T-SQL commands involved or used to produce test objects/data.
*/
Export-DbaCredential -SqlInstance server -Identity Credential_Name -Verbose

Expected Behavior

There are 2 bugs:

  1. Flag -Identity doesn't work. It doesn't filter.
    how I understood this could be fixed by changing
    in Export-DbaCredential.ps1 file 81 row:
    $InputObject = $InputObject | Where-Object Identity -in $Identity
    to
    $InputObject = $InputObject | Where-Object Name -in $Identity

  2. Also I receive error with DAC when executes this function in MS SQL Server log:

and after this execution there exists DAC process with sleeping status:
(you can check it by this query)

SELECT
en.name,
CASE
WHEN ses.session_id= @@SPID THEN 'It''s me! '
ELSE '' END 
+ coalesce(ses.login_name,'???') as WhosGotTheDAC,
ses.session_id,
ses.login_time,
ses.status,
ses.original_login_name
from sys.endpoints as en
join sys.dm_exec_sessions ses on
en.endpoint_id=ses.endpoint_id
where en.name='Dedicated Admin Connection'

Actual Behavior

VERBOSE: [13:24:06][Export-DbaCredential] Getting NetBios name for [server].
VERBOSE: [13:24:06][Export-DbaCredential] Checking if Remote Registry is enabled on [server].
VERBOSE: [13:24:06][Get-DecryptedObject] Querying service master key
VERBOSE: [13:24:06][Get-DecryptedObject] Get entropy from the registry - hopefully finds the right SQL server instance
VERBOSE: [13:24:06][Get-DecryptedObject] Decrypt the service master key
VERBOSE: [13:24:06][Get-DecryptedObject] Choose the encryption algorithm based on the SMK length - 3DES for 2008, AES
for 2012
VERBOSE: [13:24:06][Get-DecryptedObject] Query link server password information from the Db.
VERBOSE: [13:24:06][Get-DecryptedObject] Get entropy from the registry
VERBOSE: [13:24:06][Get-DecryptedObject] Go through each row in results


    Directory: C:\Users\\Documents


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        4/30/2019   1:24 PM            521 [server]-04302019132406-credential.sql
VERBOSE: [13:24:06][Export-DbaCredential] Attempting to migrate
-a----        4/30/2019   1:24 PM            521 [server]-04302019132406-credential.sql
@asnest
Copy link
Author

asnest commented Apr 30, 2019

Error from 2nd bug:
Could not connect because the maximum number of '1' dedicated administrator connections already exists. Before a new connection can be made, the existing dedicated administrator connection must be dropped, either by logging off or ending the process. [CLIENT: 127.0.0.1]

@sqllensman
Copy link
Contributor

The first bug cannot be resolved simply by adding
$InputObject = $InputObject | Where-Object Name -in $Identity

While this would fix the filtering of $InputObject the implementation of $InputObject is broken.
It does not accept value from Pipeline and also is not actually used when building the script

The credentials used in script are obtained from code

$creds = Get-DecryptedObject -SqlInstance $server -Type Credential

This does not use either $InputObject or $Identity to filter.
The code need some modification in order to work correctly.

The issue with DAC being left open is also caused by Get-DecryptedObject
This creates a connection via DAC but does not properly close the connection.

Reason for this is explained in
https://stackoverflow.com/questions/4959885/why-does-sqlconnection-close-not-close-the-login

Adding Pooling=false; to the connection string as per the above article will resolve the second issue.

@sqllensman sqllensman self-assigned this May 1, 2019
@asnest
Copy link
Author

asnest commented May 1, 2019

Thank you for the fast response!
I hope these silly issues will be fixed :)

@potatoqualitee
Copy link
Member

Calling issues, and ultimately our work, "silly" is disrespectful, @asnest. We would appreciate if your words would reflect appreciation for the incredible amount of work we put into developing this toolset.

@sqllensman, thank you for the time you've invested into researching and resolving this issue.

@asnest
Copy link
Author

asnest commented May 1, 2019

@potatoqualitee Sorry, I didn't want to show any disrespect.
I appreciate work you do and also want to improve the quality of this product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants