After installing SQL Server Express 2008 R2 using SQLEXPRWT_x86_ENU.exe, SQL Server can't create database

StackOverflow https://stackoverflow.com/questions/12430422

  •  02-07-2021
  •  | 
  •  

Question

I have an NSIS install script which successfully installs an instance of SQL Server Express 2008 R2 on Windows 7, but when I later try to create a database from the install script I get an error saying access denied. My detailed steps follow.

I install SQL Server Express with my NSIS installer using the following:

ExecWait 'SQLEXPRWT_x86_ENU.exe /Q /ACTION=Install /IACCEPTSQLSERVERLICENSETERMS /ROLE=AllFeatures_WithDefaults /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /INSTANCENAME=SQLXXXX /SecurityMode=SQL /SAPWD="xxxxxx" /IndicateProgress'

Then within my NSIS installer I 'try' to create a database with the following:

ExecWait 'sqlcmd -S "computerName\SQLXXXX" -i "$OUTDIR\ASPNETDB_Create.SQL" -o "$OUTDIR\ASPNETDB_Create_Log.txt"'

The script ASPNETDB_Create.SQL fails at the first command in it which follows:

CREATE DATABASE [aspnetdb] ON  PRIMARY 
( NAME = N'aspnetdb', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA\aspnetdb.mdf' , SIZE = 411392KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) 
LOG ON ( NAME = N'aspnetdb_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA\aspnetdb_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

I get the following error listed:

CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA\aspnetdb.mdf'.

It seems the problem is that the folder 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA' doesn't have any permissions set for user "NT AUTHORITY\Network Service".

If incorrect access permissions are indeed my problem, how can I set the correct permissions on the DATA directory where the database will reside?

Was it helpful?

Solution

You can change the ACL with the AccessControl plugin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top