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

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?

You can change the ACL with the AccessControl plugin

Related

Installing MS SQL Server Express 2017 with Inno Installer

I'm desperately trying to install SQL Server Express 2017 with Inno Installer.
Within my installer I include the extracted installer files.
That means that I already executed the common SQLEXPR_x64_ENU.exe, to avoid the "extract-temp-folder" prompt while my installer is running.
I execute the following on the cmd:
{somePath}\SQLEXPR_x64_ENU\setup.exe /ACTION=Install /Q /SKIPRULES=RebootRequiredCheck /SUPPRESSPRIVACYSTATEMENTNOTICE=1 /IAcceptSQLServerLicenseTerms=1 /SECURITYMODE=SQL /SAPWD=secretPW /ConfigurationFile=ConfigurationFileExpr.ini
The install succeeds.
But when I do the same within my InnoInstaller-File like this:
...
[Files]
Source: "SQLEXPR_x64_ENU\*"; DestDir: "{tmp}\SQLEXPR_x64_ENU"; Check: not SQLExpress_Check; Flags: recursesubdirs;
[Run]
Filename: "{tmp}\SQLEXPR_x64_ENU\setup.exe"; Description: "Installing SQL Server Express 2017..."; StatusMsg: "Installing SQL Server Express 2017..."; \
Parameters: "/ACTION=Install /Q /SKIPRULES=RebootRequiredCheck /SUPPRESSPRIVACYSTATEMENTNOTICE=1 /IAcceptSQLServerLicenseTerms=1 /SECURITYMODE=SQL /SAPWD=secretPW /ConfigurationFile=ConfigurationFileExpr.ini"; Check: not SQLExpress_Check; Flags: runascurrentuser;
...
SQL Installer fails with the following error:
Exception type: System.MissingMethodException
Message:
Method not found: 'Void Microsoft.SqlServer.Chainer.Infrastructure.RoleService.Initialize(Microsoft.SQL.Chainer.Product.RolesType)'.
HResult : 0x80131513
Data:
DisableWatson = true
Stack:
at Microsoft.SqlServer.Configuration.BootstrapExtension.InitializeRoleServiceAction.ExecuteAction(String actionId)
at Microsoft.SqlServer.Chainer.Infrastructure.Action.Execute(String actionId, TextWriter errorStream)
at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.<>c__DisplayClasse.<ExecuteActionWithRetryHelper>b__b()
at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.ExecuteActionHelper(ActionWorker workerDelegate)
Is this a permission error?
I do not have a clue.
On cmd-shell it works, but not on InnoInstaller.
Thanks in advance for your efforts and have a nice day.
Solution for me was provided by Gavin Lambert on the Inno Setup Forum :
If you're [installing from the directory of unpacked files], you need to use {sd}\shortname as the DestDir (usually combined with deleteafterinstall) -- you can't put the files in {tmp} or any similar path as the files are very deeply nested and the db installer ends up failing to access some files because the path is too long.
If you use an unpacked installer file, here is what should work absolutely perfect.
SQLEXPR_x64_ENU.exe /x:%temp%\SQLEXPR_x64_ENU\ /QS /ACTION=Install /SKIPRULES=RebootRequiredCheck /SUPPRESSPRIVACYSTATEMENTNOTICE=1 /IAcceptSQLServerLicenseTerms=1 /SECURITYMODE=SQL /SAPWD=secretPW /ConfigurationFile=ConfigurationFileExpr.ini
In the above command, /x:%temp%\SQLEXPR_x64_ENU\ is the very important switch where it describes the extraction location and with combination to /QS it will show you the progress on screen but will not ask for any input.
You may have to change %temp% to appropriate command to grab a windows temporary folder in your installer. The command I have posted is good for command-line execution.
Enjoy! :)

cannot open shared object file : No such file or directory

I installed postgresql-9.3 in linux server 7.1 redhat & postgis93-2.1.8
after that i created New Database and executed the Query in Query Window
"Create extension postgis"
it showing error like below
ERROR: could not load library "/opt/Postgresql/9.3/lib/postgresql/rtpostgis-2.1.so":libpng12.so.0:cannot open shared object file : No such file or directory sql state 58p01
I installed backage libpng12.so.0 correctly
file in the location og /usr/lib/
Kindly let me know where i am wrong

Creating backup of my .mdf DB file during runtime

when i try to use this code for creating backup of my DB this error occures ?
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.ShowDialog();
File.Copy(#"C:\Program Files\Microsoft SQLServer\MSSQL10.MSSQLSERVER\MSSQL\DATA\MyDB.mdf", dlg.FileName );
The process cannot access the file 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MyDB.mdf' because it is being used by another process.

How to silently/automatically install Desktop Experience in Azure?

I need to install Desktop Experience in Azure Worker Role. Installing DE via the command line can be done with:
c:\servermanagercmd -install Desktop-Experience
And then a reboot is required.
How can I best make this work in Azure Worker Role?
UPDATE:
1) Make sure to use OS Family 2 and SDK >=1.3
2) Use elevated startup task to call included batchfile with this command:
3) servermanagercmd -install Desktop-Experience -restart -resultPath results.xml
I have tried
a) to put that commandline in a batch/.cmd file and run it via an elevated startup task. Result: The worker role keeps Aborting and restarts in a neverending loop.
b) I have tried to create a new Process() in OnStart(), under elevated runtime, something like this:
ServiceDefinition.csdef:
Runtime executionContext="elevated"
WorkerRole.cs:
public override bool OnStart()
{
if (!System.IO.File.Exists("Startup\\InstallationFinished.txt"))
{
Process startup = new Process();
startup.StartInfo.FileName = "Startup\\InstallDesktopExperience.cmd";
startup.StartInfo.CreateNoWindow = true;
startup.EnableRaisingEvents = true;
startup.Start();
startup.WaitForExit();
System.IO.File.WriteAllText("Startup\\InstallationFinished.txt",
"Installation is complete.");
startup.StartInfo.FileName = "Startup\\Reboot.cmd";
startup.Start();
}
base.OnStart();
}
InstallDesktopExperience.cmd:
servermanagercmd -install Desktop-Experience
Reboot.cmd:
shutdown /r
The result is that the Event Viewer in the Azure Worker Role shows an exception from TrustedInstaller (0xc0000005). After this error is shown in the event log, DE cannot be installed manually by opening a command line window and typing the command either. I get the error:
Error: Installation of [Desktop Experience] failed. Attempt to install Desktop Experience failed with error code 0x80080005. Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))
(but it works by doing it manually in a command line window if I haven't run the code in OnStart)
I'm lost. Thanks in advance for any and all suggestions.
You should reference this guide from Wage Wegner. It deals with Expression Encoder, but the prereq of Desktop Experience is exactly the same:
http://www.wadewegner.com/2011/01/using-expression-encoder-4-in-a-windows-azure-worker-role/
Snippet from the same, but you should take the time to read his explanation on some of these concepts
REM : Install the Desktop Experience
ServerManagerCMD.exe -install Desktop-Experience -restart -resultPath results.xml
REM : Make a folder for the AppData
md "%~dp0appdata"
REM : Change the location of the Local AppData
reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d "%~dp0appdata" /f
REM : Install Encoder
"%~dp0\webpicmd\WebPICmdLine.exe" /accepteula /Products: ExpressionEncoder4 /log:encoder.txt
REM : Change the location of the Local AppData back to default
reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d %%USERPROFILE%%\AppData\Local /f
REM : Exit gracefully
exit /b 0

How to install SQL Server 2008 Express with Inno Setup?

anyone have script or procedures to install SQL Server 2008 Express, set up the database for the app and finally install a client .NET WinForm application?
In situations like this where I'm relying on third-party products (SQL Server Express), I tend to use command-line driven installs (either directly in a cmd file or called from a 'proper' install tool). This site shows you how to install Express from the command line, then you can use the SQL Express utility for object creation. This method is 'blessed' by Microsoft.
Sometimes the simplest solution is the best, even if that means getting the user of my product to install SQL Express separately before running my install. Well, best for me, anyway :-)
The following script will check for the full version of SQL Server 2008 R2. If full version is already installed, then it skips installing the SQL Server. If the full version is not installed, then it checks for the SQL Express edition. If it is already installed, it will skip the installation. If it is not installed, then it will install SQL Express 2008 R2.
Create a new script. Let's name it sql2008express.iss with the following content
[CustomMessages]
sql2008r2expressx86_title=Microsoft SQL Server 2008 R2 Express Edition x86 (Including Tools)
sql2008r2expressx64_title=Microsoft SQL Server 2008 R2 Express Edition x64 (Including Tools)
sql2008r2expressx86_size=235.5 MB
sql2008r2expressx64_size=247.5 MB
[Code]
const
sql2008r2expressx86_url='http://download.microsoft.com/download/5/5/8/558522E0-2150-47E2-8F52-FF4D9C3645DF/SQLEXPRWT_x86_ENU.exe';
sql2008r2expressx64_url='http://download.microsoft.com/download/5/5/8/558522E0-2150-47E2-8F52-FF4D9C3645DF/SQLEXPRWT_x64_ENU.exe';
procedure sql2008express();
var
version: string;
begin
// Check if the full version fo the SQL Server 2008 R2 is installed
RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Microsoft SQL Server\SQLSERVER\MSSQLServer\CurrentVersion', 'CurrentVersion', version);
if (version < '10.5') or (version = '') then begin
// If the full version is not found then check for the Express edition
RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\CurrentVersion', 'CurrentVersion', version);
if (version < '10.5') (*or (version > '9.00') or (version = '') *) then begin
if isX64() then
AddProduct('SQLEXPRWT_x64_ENU.exe', '/QS /IACCEPTSQLSERVERLICENSETERMS /ACTION=Install /FEATURES=SQL,AS,RS,IS,Tools /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSYSADMINACCOUNTS="builtin\Administrators" /INDICATEPROGRESS /TCPENABLED=1 /BROWSERSVCSTARTUPTYPE=Automatic /ERRORREPORTING=0 /SQMREPORTING=0 /SECURITYMODE=SQL /SAPWD=1234', CustomMessage('sql2008r2expressx64_title'), CustomMessage('sql2008r2expressx64_size'), sql2008r2expressx64_url,false,false)
else
AddProduct('SQLEXPRWT_x86_ENU.exe', '/QS /IACCEPTSQLSERVERLICENSETERMS /ACTION=Install /FEATURES=SQL,AS,RS,IS,Tools /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSYSADMINACCOUNTS="builtin\Administrators" /INDICATEPROGRESS /TCPENABLED=1 /BROWSERSVCSTARTUPTYPE=Automatic /ERRORREPORTING=0 /SQMREPORTING=0 /SECURITYMODE=SQL /SAPWD=1234', CustomMessage('sql2008r2expressx86_title'), CustomMessage('sql2008r2expressx86_size'), sql2008r2expressx86_url,false,false);
end;
end;
end;
In your script then just include the script i nthe [Run] tag and call the previous created script in the [Code] tag like below:
[Run]
`#include "scripts\sql2008express.iss"
[Code]
sql2008express();
Other notes:
- If the setup kits for the SQL are found in the same folder then it will use them, if not, they will be downloaded from the Internet.
- Sorry for the formating, it doesn't work. Copy/paste it in a text editor and format it. It is complete and working.
I hope this will help others too. :)

Resources