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

xSQLServerHelper: Function Connect-SQL returns successfull even when connection fails #333

Closed
johlju opened this issue Jan 23, 2017 · 3 comments · Fixed by #799
Closed
Labels
bug The issue is a bug.

Comments

@johlju
Copy link
Member

johlju commented Jan 23, 2017

Details of the scenario you try and problem that is occurring:

When running the following

$sql = New-Object Microsoft.SqlServer.Management.Smo.Server 'sqltest\Default'

An empty object is returned.

AuditLevel                  : 
BackupDirectory             : 
BrowserServiceAccount       : 
BrowserStartMode            : 
BuildClrVersionString       : 
BuildNumber                 : 
ClusterName                 : 
ClusterQuorumState          : 
ClusterQuorumType           : 
Collation                   : 
CollationID                 : 
ComparisonStyle             : 
ComputerNamePhysicalNetBIOS : 
DefaultFile                 : 
DefaultLog                  : 
Edition                     : 
ErrorLogPath                : 
FilestreamLevel             : 
FilestreamShareName         : 
HadrManagerStatus           : 
InstallDataDirectory        : 
InstallSharedDirectory      : 
InstanceName                : 
IsCaseSensitive             : 
IsClustered                 : 
IsFullTextInstalled         : 
IsHadrEnabled               : 
IsSingleUser                : 
Language                    : 
LoginMode                   : 
MailProfile                 : 
MasterDBLogPath             : 
MasterDBPath                : 
MaxPrecision                : 
NamedPipesEnabled           : 
NetName                     : 
NumberOfLogFiles            : 
OSVersion                   : 
PerfMonMode                 : 
PhysicalMemory              : 
PhysicalMemoryUsageInKB     : 
Platform                    : 
Processors                  : 
ProcessorUsage              : 
Product                     : 
ProductLevel                : 
ResourceLastUpdateDateTime  : 
ResourceVersionString       : 
RootDirectory               : 
ServerType                  : 
ServiceAccount              : 
ServiceInstanceId           : 
ServiceName                 : 
ServiceStartMode            : 
SqlCharSet                  : 
SqlCharSetName              : 
SqlDomainGroup              : 
SqlSortOrder                : 
SqlSortOrderName            : 
Status                      : 
TapeLoadWaitTime            : 
TcpEnabled                  : 
VersionMajor                : 
VersionMinor                : 
VersionString               : 
Name                        : sqltest\Default
Version                     : 
EngineEdition               : 
ResourceVersion             : 
BuildClrVersion             : 
DefaultTextMode             : True
Configuration               : Microsoft.SqlServer.Management.Smo.Configuration
AffinityInfo                : 
ProxyAccount                : 
Mail                        : 
Databases                   : 
Endpoints                   : 
Languages                   : 
SystemMessages              : 
UserDefinedMessages         : 
Credentials                 : 
CryptographicProviders      : 
Logins                      : 
Roles                       : 
LinkedServers               : 
SystemDataTypes             : 
JobServer                   : 
ResourceGovernor            : 
ServiceMasterKey            : 
Settings                    : Microsoft.SqlServer.Management.Smo.Settings
Information                 : Microsoft.SqlServer.Management.Smo.Information
UserOptions                 : Microsoft.SqlServer.Management.Smo.UserOptions
BackupDevices               : 
FullTextService             : 
ActiveDirectory             : 
Triggers                    : 
Audits                      : 
ServerAuditSpecifications   : 
AvailabilityGroups          : 
ConnectionContext           : Data Source=sqltest\Default;Integrated Security=True;MultipleActiveResultSets=False;Application Name="SQL Management"
Events                      : Microsoft.SqlServer.Management.Smo.ServerEvents
OleDbProviderSettings       : 
Urn                         : 
Properties                  : 
UserData                    : 
State                       : Existing
IsDesignMode                : False
DomainName                  : SMO
DomainInstanceName          : 

Instead of validating using the following, and throw an error is it is true.

if (!$sql)

Validation should use

if (-not $sql.Status -eq 'Online' )

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:
n/a

Version of the DSC module you're using, or 'dev' if you're using current dev branch:
Dev

@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Jan 23, 2017
@randomnote1
Copy link
Contributor

Funny thing that I've seen with the status is the property doesn't update until you actually get another property. I normally query the version to make sure I'm connected.

@johlju
Copy link
Member Author

johlju commented Jan 23, 2017

If you just use $sql in this case, it returns 'sqltest\Default' (using ToString() or something) which is whatever you tried to connect with. So you are right, must use one of the properties. Only when you use one of the properties it actually connects (each time you use a property apparently).

I thought Status -eq 'Online' was better, so it throws if the SQL server is in any other state.

@randomnote1
Copy link
Contributor

I'm working on this one.

@johlju johlju added in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Sep 11, 2017
johlju pushed a commit that referenced this issue Sep 14, 2017
- Changes to xSQLServerHelper
  - Fixed Connect-SQL by ensuring the Status property returns 'Online' prior to
    returning the SQL Server object (issue #333).
@johlju johlju removed the in progress The issue is being actively worked on by someone. label Sep 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants