How to install SQL Server Express as another user when installing via Chocolatey in a Dockerfile

fhity93d  于 2023-05-05  发布在  SQL Server
关注(0)|答案(1)|浏览(145)

I'm trying to update some teamcity build agent docker containers. We now need to have SQL Server Express installed on the build agents. We're using chocolatey to install other programs on the container in the dockerfile, so I've added RUN choco install sql-server-express -y to the dockerfile.

However when teamcity tries to access the SQL Server, it receives an error: `
System.Data.SqlClient.SqlException : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

I opened a powershell window into the build agent and attempted to connect to the SQL server using $sqlConnection.ConnectionString = "Data Source=$env:computername\SQLEXPRESS;Integrated Security=true;" , however there was another error there as well:

Exception calling "Open" with "0" argument(s): "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

Checking the event logs, I found the following errors:

  • SQL Server could not spawn FRunCommunicationsManager thread. Check the SQL Server error log and the operating system error log for information about possible related problems.
  • Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.
  • TDSSNIClient initialization failed with error 0x5, status code 0x1. Reason: initialization failed with an infrastructure error. Check for previous errors. Access is denied.
  • TDSSNIClient initialization failed with error 0x5, status code 0x51. Reason: Unable to configure MDAC-compatibility Named Pipes protocol pipe name in registry. Access is denied.

Which seems similar to the problem here: SQL Server 2014 SP2 does not start on Windows Docker , and I believe is caused because the containeradministrator account (the default user account in the container) is not being given the correct permissions to edit a registry key that is required to open the pipe.

I have tried loading the container up without installing SQL, then powershelling in and installing SQL with chocolatey as the containeradministrator, and when done this way, the server connection works. I also ran a whoami right before the dockerfile ran the chocolatey install script, and it shows containeradministrator. However for some reason, when installed in the dockerfile, the user does not receive the correct permissions.

I am unsure how to correct this issue.

Another similar issue: SQL Server can't auth user when installed witch chocolatey (via chef)

nnt7mjpx

nnt7mjpx1#

Try this format to adapt your PowerShell script to a Dockerfile build:

RUN choco install sql-server-express -o -ia "'/q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine,Fulltext /UPDATEENABLED=0 /SQLSVCACCOUNT=\"NT AUTHORITY\System\" /SQLSYSADMINACCOUNTS=\"BUILTIN\ADMINISTRATORS\" /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS'" -f -y

Inspired by the comment section here:
https://community.chocolatey.org/packages/sql-server-express

相关问题