Skip to content

Conversation

@yoke88
Copy link

@yoke88 yoke88 commented Jul 1, 2020

Type of Change

  • Bug fix (non-breaking change, fixes [Bug] Microsoft.SqlServer.Management.Smo.Server object may return null computername  #6632 )
  • New feature (non-breaking change, adds functionality, fixes # )
  • Breaking change (effects multiple commands or functionality, fixes # )
  • Ran manual Pester test and has passed (`.\tests\manual.pester.ps1)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/sqlcollaborative/appveyor-lab ?
  • Nunit test is included
  • Documentation
  • Build system

Purpose

[Microsoft.SqlServer.Management.Smo.Server may return null computername ,so Resolve-NetBiosName、Resolve-SqlIpAddress will return null too, and cause other function fails.

PS C:\> [Microsoft.SqlServer.Management.Smo.Server]"mydb"|fl *name*


ClusterName                 :
ComputerNamePhysicalNetBIOS : MYDB
FilestreamShareName         : MSSQLSERVER
InstanceName                :
NamedPipesEnabled           : False
NetName                     : MYDB
ServiceName                 : MSSQLSERVER
SqlCharSetName              : cp936
SqlSortOrderName            : bin_ascii_8
Name                        : mydb
DomainName                  : SMO
DomainInstanceName          : MYDB

Approach

modify Resolve-NetBiosName and Resolve-SqlIpAddress to handle null computername .

Commands to test

Screenshots

image

Learning

yoke88 added 5 commits July 1, 2020 10:43
Microsoft.SqlServer.Management.Smo.Server object may return null computername , we need resolve such situation
using datalength to replace len, which will works on sql 2012,2014,2016
handle null computername
handle null computername
# key_id 102 eq service master key, thumbprint 3 means encrypted with machinekey
Write-Message -Level Verbose -Message "Querying service master key"
$sql = "SELECT substring(crypt_property,9,len(crypt_property)-8) as smk FROM sys.key_encryptions WHERE key_id=102 and (thumbprint=0x03 or thumbprint=0x0300000001)"
$sql = "SELECT substring(crypt_property,9,datalength(crypt_property)-8) as smk FROM sys.key_encryptions WHERE key_id=102 and (thumbprint=0x03 or thumbprint=0x0300000001)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What purpose does this change serve?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LEN returns the number of characters in the string, DATALENGTH returns the number of bytes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just see it here and did a test on my env and it works:
bugal/Powershell-Modules@606153b

there are other fix to workground for SQL cluster too ,you may need this NetSPI/Powershell-Modules#9

@wsmelton
Copy link
Member

wsmelton commented Jul 1, 2020

I'm closing this PR as this change and the error provided are not reproducible by our test or manual testing I've done in my lab.

Discussion can continue in your issue.

@wsmelton wsmelton closed this Jul 1, 2020
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 this pull request may close these issues.

[Bug] Microsoft.SqlServer.Management.Smo.Server object may return null computername

2 participants