SQL Server database backup: Network Service file access - sql-server

When trying to run the following database backup command from my code I get an "Operating system error 5(Access is denied.)" error. This is because the log on account for the SQL Server Windows Service is 'Network Service' and that does not have access to right to this folder.
BACKUP DATABASE [AE3DB] TO DISK = 'c:\AE3\backup\AE3DB.bak'
My question is, from my code how would I go about figuring out where on the C drive 'Network Service' is allowed to right the backup to?
NOTE: This is a distributed application so I cannot easily change the log on for the SQL Server Windows Service to the 'Local System' account that would be able to right to that folder.

You don't go about searching for random places on C:\ where the SQL Server service account has write access...
You can choose between:
place the backups in the SQL Server backup location. This is specified during setup and it is properly ACL'ed so that the service account has all the necessary permissions. See 'Backup Directory' in http://msdn.microsoft.com/en-us/library/cc281941.aspx
place the backup in a well known location that you create and you ACLit for proper permissions for the SQL Server service account. You should not grant permission to the service account itself (NETWORK SERVICE in this casE) but instead grant to the SQL Server administrative service group: SQLServerMSSQLUser$ComputerName$MSSQLSERVER. See http://msdn.microsoft.com/en-us/library/ms143504.aspx

The whole point of Network Service account is to not have rights to the local disk. This prevents network based security holes.
My guess is your server is locked down which means you have to log in locally to do a backup or use the administrative account to do so remotely.

Related

Using AWS FSx file share for SQL Server Backup Directory

I'm trying to use an FSx file share as the Backup directory when installing SQL Server Express on my EC2 instance, but the SQL installer fails to use the UNC path to the FSx file share due to a SeSecurityPrivilege problem.
I can access the file share on FSx with full access from the EC2 instance using File Explorer, but do not know how to set the SeSecurityPrivilege as I don't think it is possible to access the File Server for the FSx share as proposed in the error message from the SQL installer below.
Any ideas would be appreciated?
The error is this:
"SQL Server setup account does not have the SeSecurityPrivilege privilege on the specified file server in the path . This privilege is needed in folder security setting action of SQL Server setup program. To grant this privilege, use the Local Security Policy console on this file server to add SQL Server setup account to "Manage auditing and security log" policy. This setting is available in the "User Rights Assignments" section under Local Policies in the Local Security Policy console."
The error indicates that the account used to install SQL server doesn't have the "SeSecurityPrivilege" permission on the FSX servers which is required to perform the installation.
By default, the FSx Delegated Administrators Group has this permission.
You need to add your user account to that group on your FSx Windows File System along with Full control on the share and full control on the ntfs.
The problem is that you connected to this machine with the windows/machine administrative. you should connect to this machine with the Active directory administrative user and follow the below document.
https://aws.amazon.com/blogs/storage/simplify-your-microsoft-sql-server-high-availability-deployments-using-amazon-fsx-for-windows-file-server/

SSIS cannot access folder which everyone has access to

So we have a network address lets call it the Z drive that everyone has access to.
By everyone I mean the entire organization. For completeness, I actually went ahead and gave access to the actual SQL Server Agent.
The package runs fine on dev, but always fails with
The directory "Z:\SSIS_Test" does not exist
At first, I thought it was an issue of access. But how can't the SQL Server Agent access an everyone drive?
Also, I went in and run the package on the server myself as the caller and it still failed with same error. What gives? Am I not getting something?
Possible solutions
(1) Granting service accounts
Try giving read/write permissions to the SQL Database Engine Service account NT SERVICE\MSSQL$<Instance Name> and NT SERVICE\SQLSERVERAGENT (Where <Instance Name> should be replaced by the installed instance name):
Configure File System Permissions for Database Engine Access
I was facing the same issue, it looks like the "everyone" permission does not take into consideration service accounts (I am not sure). The issue was solved after granting the database engine and SQL agent service accounts. Also feel free to read more about SQL Server service account in the following documentation:
Configure Windows Service Accounts and Permissions
(2) Mapping drive within SQL Server
You can refer to the following article for more information:
Make Network Path Visible For SQL Server Backup and Restore in SSMS
Or you can try to use the full UNC path instead of the mapped drive.
If these solutions didn't worked, there are many other suggestions listed in the following answer, you can check it for more information:
SSIS File System Task Error while copying files between servers

TFS 2015 - TF401002: The SQL Server Database Engine failed to save the database backup to path

When attempting to create scheduled backups for TFS 2015, I received the following message: "TF401002: The SQL Server Database Engine failed to save the database backup to path \{share}\d$\TFSBackups. Please grant SQL service account read/write access to that folder."
I can't seem to find a solution that will work for me. The 'TFSBackups' folder is shared with full permissions for the NETWORK SERVICE and MSSQLSERVER.
What haven't I done?
Put the comment from Panagiotis Kanavos in the answer.
The error message is crystal clear and has nothing to do with TFS.
That account doesn't have permission to write to that folder.
The path is NOT a path to a valid share, it uses the administrative
endpoint d$ to directly access a physical drive. Only administrators
are allowed to use administrative endpoints.
Just share TFSBackups, set the proper permissions and use the share's
path, eg \\MyStorageMachine\TFSBackups
Normally SQL Service is running at user NT Authority/SQLAgent or similar(these users doesn't have authorization to tfs network folder). Go services and change owner of service to an account which has access to tfs folder.
I had the same problem with TFS, You must be setting up TFS Backups using TFS Admin console.
It is actually the SQL service which write and read backup files to the said location.
Just make sure you grant access to the SQL Service accounts.
If you're on Domain pay attention to Domain User Name.
In my case, SQL Server engine was executed by domain user User#Domain.com but my true permission was for Domain\User so fixing user Logon as in SQL engine saved my day.
Most of the time NT Authority doesn't have write permission on network path so, you need to change Azure or TFS owner user to valid network user.

Error “TF400998: The current user failed to retrieve the SQL Server service account information” when trying to configure backup plan in TFS 2015

This is a "Answer Your question" type of the post. Just hope the information here will help anyone.
Situation:
Migrated TFS from Machine A to Machine B
Restored the DB
Reconfigured DBs using TfcConfigure RemapDB
Changed service account, url, binding and etc.
domainname\TFSService = service account to run TFS
Problem:
Logged on as the domainname\TFSService
Tried to setup "Scheduled backups for TFS" using a domain account used as a service account for running TFS (HOWTO)
Back up should be stored on a remote server (accessible over UNC)
ERROR = Error “TF400998: The current user failed to retrieve the SQL Server service account information” when trying to configure backup plan in TFS 2015
Question:
How to setup the Scheduled Backup using TFSService account?
Solution:
Give domainname\TFSService account local Administrator permissions on Your TFS Server
Give domainname\TFSService account the sysadmin role in Your SQL Instance used to run TFS
Five domainname\TFSService account Log on as a service permissions on the TFS Server (HOWTO)
(IMPORTANT!!!) Run SQL Server Service hosting TFS DBs AS domainname\TFSService (HOWTO)
(IMPORTANT!!!) Give 'Full permissions' for the account used to run the SQL Service on the UNC destination folder.
Example: If SQL Server Account = domainname\TFSService, than permissions on the UNC should also be given to domainname\TFSService
Rerun the TFS "Scheduled Backup" configuration. Should resolve the error.
Sorry if this obvious or straight forward and considered as spam/flooding. Just spent over 3-4 hours. Hopefully this helps people save time and nerves.
In TFS2015 simply make sure that:
Make sure MachineA and MachineB are in the domain and a user "yourDomain\username" is added Application Tier >> Administration Console Users
Take Full Backup Now throw Scheduled Backups and move the backup to MachineB network share, as a restore process might fail throw network.
Open TFS Admin console on MachineB and Remove Application Tier feature if exists.
Use SQL Managment Studio to remove Tfs_configuration and other Tfs_* databases on MachineB
In TFS Admin Console of MachineB, you will have only option to restore under Scheduled Backup.
After restoring process on MachineBLaunch the Application-Tier Onlywizard (right click on Application Tier in TFS Admin Console).In Databases, specify the new SQL Server instance(MachineB/sqlexpress`) where you restored the TFS databases

SQL Server Backup to Network Share:Access is Denied

I am trying to setup a new job to backup two sql server databases to a network share twice a day. I set the job up, and ran it manually for a test and it failed with access is denied (os error 5). I forgot to request access to the share for the sql server service account.
I requested the access and it was granted, but now I am stilling getting access is denied when I try and run the backup or access the share via xp_cmdshell.
I have verified that the sql server service account has read/write access to the share by doing the following.I logged in to the sql server via rdp with the account, navigating to the share and creating/deleting files. I also checked in properties>securities>advanced>effective permissions. The sql server account is shown as having read/write/modify permissions there as well.
I do have other jobs running in this instance that use different network shares with out any problems, so I am currently stumped. Any suggestions?

Resources