dsccommunity / SqlServerDsc

This module contains DSC resources for deployment and configuration of Microsoft SQL Server.
MIT License
359 stars 224 forks source link

xSQLServerSetup: Fails to start Database Engine service for SQL Server 2008 R2 #270

Closed johlju closed 7 years ago

johlju commented 7 years ago

Details of the scenario you try and problem that is occurring: In rare occasions when installing SQL Server 2008 R2 (or first instance) the Database Engine service are not started, so Set-method fails when it cannot verify with Test-method. First it installs SQL2008R2 which fails, next it installs SQL2012 and that instance is started without problems.

LCM verbose log:

VERBOSE: [SQLTEST]: LCM:  [ Start  Resource ]  [[xSQLServerSetup]InstallSql2008R2Instance]
VERBOSE: [SQLTEST]: LCM:  [ Start  Test     ]  [[xSQLServerSetup]InstallSql2008R2Instance]
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-28-38: Using path: \\file.company.local\images\SQL2008R2SP3-ENT\setup.exe
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-28-39: Features found: ''
VERBOSE: [SQLTEST]: LCM:  [ End    Test     ]  [[xSQLServerSetup]InstallSql2008R2Instance]  in 1.1950 seconds.
VERBOSE: [SQLTEST]: LCM:  [ Start  Set      ]  [[xSQLServerSetup]InstallSql2008R2Instance]
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-28-39: Using path: \\file.company.local\images\SQL2008R2SP3-ENT\setup.exe
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-28-39: Robocopy is copying media from source '\\file.company.local\images\SQL2008R2SP3-ENT' to destination 'C:\Windows\TEMP\SQL2008R2SP3-ENT'
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-28-50: Using path: C:\Windows\TEMP\SQL2008R2SP3-ENT\setup.exe
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-28-50: Starting setup using arguments: /Quiet="True" /IAcceptSQLServerLicenseTerms="True" /Action="Install" /SQLSVCACCOUNT="COMPANY\svcSql" /SQLSVC
PASSWORD="********" /AGTSVCACCOUNT="COMPANY\svcSql" /AGTSVCPASSWORD="********" /AGTSVCSTARTUPTYPE=Automatic /InstanceName="SQL2008R2" /Features="SQLENGINE,SSMS,ADV_SSMS" /BrowserSvcStartupType="Automatic" /SQLCollation="Finnish_Swedish_CI_AS" /SQLSysAd
minAccounts="COMPANY\sqladm" "COMPANY\SQL Admins" "COMPANY\sqladm"
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-28-51: Process matching path 'C:\Windows\TEMP\SQL2008R2SP3-ENT\setup.exe' started in process ID 628
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-33-42: Using path: \\file.company.local\images\SQL2008R2SP3-ENT\setup.exe
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-33-45: Detecting replication feature (HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.SQL2008R2\ConfigurationState)
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-33-46: Replication feature not detected
VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-33-46: Connected to SQL localhost\SQL2008R2
The following exception occurred while trying to enumerate the collection: "Failed to connect to server localhost\SQL2008R2.".
    + CategoryInfo          : NotSpecified: (:) [], CimException
    + FullyQualifiedErrorId : ExceptionInGetEnumerator
    + PSComputerName        : sqltest.company.local

VERBOSE: [SQLTEST]:                            [[xSQLServerSetup]InstallSql2008R2Instance] 2016-12-28_14-34-02: Features found: 'SQLENGINE,SSMS,ADV_SSMS'
VERBOSE: [SQLTEST]: LCM:  [ End    Set      ]  [[xSQLServerSetup]InstallSql2008R2Instance]  in 323.8860 seconds.
The PowerShell DSC resource '[xSQLServerSetup]InstallSql2008R2Instance' with SourceInfo 'E:\DSC\DSC-SQLTestConfig.ps1::174::13::xSQLServerSetup' threw one or more non-terminating errors while running the Set-TargetResource functionality. These errors are lo
gged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : sqltest.company.local

Event log:

Log Name:      System
Source:        Service Control Manager
Date:          2016-12-28 14:33:05
Event ID:      7045
Task Category: None
Level:         Information
Keywords:      Classic
User:          SYSTEM
Computer:      SQLTEST.company.local
Description:
A service was installed in the system.

Service Name:  SQL Server (SQL2008R2)
Service File Name:  "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008R2\MSSQL\Binn\sqlservr.exe" -sSQL2008R2
Service Type:  user mode service
Service Start Type:  auto start
Service Account:  COMPANY\svcSql
Log Name:      System
Source:        Service Control Manager
Date:          2016-12-28 14:33:20
Event ID:      7036
Task Category: None
Level:         Information
Keywords:      Classic
User:          N/A
Computer:      SQLTEST.company.local
Description:
The SQL Server (SQL2008R2) service entered the stopped state.
Log Name:      System
Source:        Service Control Manager
Date:          2016-12-28 14:33:20
Event ID:      7024
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      SQLTEST.company.local
Description:
The SQL Server (SQL2008R2) service terminated with the following service-specific error: 
There was an error installing NETWKSTA.SYS.  Press ENTER to continue.

The DSC configuration that is using the resource (as detailed as possible):

xSQLServerSetup InstallSql2008R2Instance
{
    InstanceName = $Node.Sql2008R2InstanceName
    Features = $Node.Sql2008R2InstallFeatures
    BrowserSvcStartupType = 'Automatic'
    SQLCollation = 'Finnish_Swedish_CI_AS'
    SQLSvcAccount = $SqlServiceCredential
    AgtSvcAccount = $SqlAgentServiceCredential
    ASSvcAccount = $SqlServiceCredential
    RSSvcAccount = $SqlServiceCredential
    SQLSysAdminAccounts = 'COMPANY\SQL Admins', $SqlAdministratorCredential.UserName
    SetupCredential = $SqlInstallCredential

    SourcePath = $Node.SourcePath
    SourceFolder = $Node.SourceFolderSql2008R2
    SourceCredential = $SqlInstallCredential

    SuppressReboot = $False
    ForceReboot = $False

    DependsOn = '[WindowsFeature]NetFramework35','[WindowsFeature]NetFramework45'
}

Version of the Operating System, SQL Server and PowerShell the DSC Target Node is running: Windows Server 2012 R2, SQL Server 2008 R2, PS 5.0

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

johlju commented 7 years ago

Okey, so this one is strange. I get this each time installing SQL Server 2008 R2 all of the sudden, on two different servers. Can't install it manually either. My guess is that the media has been corrupted in some way. It is the only common thing among all tests. So I'm closing this issue since it has nothing to do with the resource.

gigi81 commented 7 years ago

Hi, I'm having the same issue and found out that the error disappears when creating a sysadmin login for 'NT AUTHORITY\SYSTEM' in the sql servers login.

I guess this comes from the fact that we both use the 'SQLSysAdminAccounts' parameter

As long as the DSC resource runs as 'NT AUTHORITY\SYSTEM', if there is no login for the account, DSC will fail to connect to the server.

I think this is a bug. In my opinion the fix should be to add the 'NT AUTHORITY\SYSTEM' account as admin when the SQLSysAdminAccounts is set.

gigi81 commented 7 years ago

I actually found out that our DBA intentionally removed that account for security reasons.

Trying to use the PsDscRunAsCredential didn't work as expected (the account used to login during the Test-TargetResource is still the SYSTEM account).

So, it's not a bug in the resource itself. Anyway any idea on how to work around it would be really appreciated.