Restore Backup Access Denied - sql-server

I'm trying to restore a backup from a .bak file to a local database server and keep getting the error message.
An exception occurred while executing a Transact-SQL statement or batch.(Microsoft.SqlServer.ConnectionInfo)
Cannot open backup device 'C:\Clients\SQLitis\jMKZ.bak'. Operating system error 5(Access is denied.).
RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3201)
No idea where to even start troubleshooting this. I'm on an administrator account and have full privileges so there shouldn't be anything to deny me doing this but I'm still getting the error message.

Sounds like the service account that SQL Server runs under does not have permission to folder C:\Clients\SQLitis.
When SQL Server was installed, it hopefully was set up to use a domain user account (the "service account") that is NOT an administrator on the machine. As such, the SQL Server installer only grants permissions to the folders the SQL Server setup creates.

You need to give permission to that folder to the user account that SQL Server acts as. In my case it was NT Service\MSSQLSERVER
You can find/change the SQL Server user in SQL Server Configuration Manager. Here's a link that shows how:
http://www.bidn.com/blogs/ShawnHarrison/ssis/2134/access-denied-during-database-backup

Maybe a little hacky, but I solved the issue by copying the .bak file into the designated backup folder. That way I didn't have to change any permissions.

Related

SQL Server Management Studio access denied

I'm getting an error, says "Could not load the DLL xpstar.dll... Reason: 5(Access is denied)" right after logging into SQL Server Management Studio . Even though I can browse through the database schemas but I can't perform any action.
`My current configuration:
SQL Server Enterprise 2016
SQL Server 2016 Management Studio
Authentication mode: mixed mode`
SQL Server services
Binn folder permissions
What I've tried to figure out the cause:
Check Sql server services and they are all running.
Try connecting and performing some actions with SQLCMD (list tables, list db schemas...). It's all good.
Run SSMS as administrator.
Check permissions of BINN folder.
Disable Kaspersky Endpoint Security.
None of above steps can resolve the issue. So please kindly help me to fix it.
It turns out the folder ownership is the root cause. MSSQL and its subfolders were owned by SYSTEM. Even though Administrators group were assigned full control but They couldn't access to the folder. Probably, Kaspersky is involved. I'm not sure about that.
Solutions:
Change ownership of folder MSSQL (Drive:\Program Files\Microsoft SQL Server\MSSQLXX.MSSQLSERVER\MSSQL) from SYSTEM to Administrator.
Run SSMS as Administrator and problem is solved.

Restore SQL Server 2012 error

I backed up a database from a SQL Server 2005 using my SSMS Task and called it datalab_auth.bak.
I then tried to restore it to my SQL Server 2012 but keep getting the following error:
System.Data.SqlClient.SqlError: The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQL11\MSSQL\datalab_auth.mdf'. (Microsoft.SqlServer.SmoExtended)
I tried to set the path in the above error to have permissions of Everyone to Full. Which it is currently set to.
What am I missing?
When you are performing a restore, make sure you set the option to "Overwrite the existing database" in the restore wizard.
Check what account you are using to run the SQL service through the SQL Configuration Manager and assign permissions to the account on the file and folder.
This post might help:
mssql '5(Access is denied.)' error during restoring database
The OS error 5 is about to permissions issue on the files and folder paths, I have check my account on config manager to fix this issue.
The fix steps on my case:
open SqlServer Configuration Manager as administration
Click SqlServer Service
Right click on you sql server instance, click properties
Choose Log On tab
Account name: input your administrator account and password.
Then backup database successfully.
The environment is that, the OS is Win7 and the version of sql server is MS Sqlserver 2012
This worked for me. After you select your database to restore, select file option and check realocate all files to folder

Elevated Rights Error when trying to deploy SSIS packages to a remote server

this is a new staging server with SQL 2008. I'm not famliary with SSIS that much so trying to deploy a couple packages. So I do the following in BIDS..which is probably typical:
Right-click my solution, go to properties, then go to the deployment utility tab
Change CreateDeploymentUtility to true
Go and find the .SSISDeploymentManifest file locally on my machine
Run it and try to perform a SQL Server deployment to the customer's remote server (we're running vpn to get to it)
I put in the fully qualified remote server's name, my windows auth or SQL account (I tried both ways)
Try to click now the Package Path and get this:
TITLE: Package Installation Wizard
An OLE DB error 0x80040E09 (The EXECUTE permission was denied on the object 'sp_ssis_listpackages', database 'msdb', schema 'dbo'.) occurred while enumerating packages. A SQL statement was issued and failed.
ADDITIONAL INFORMATION:
An OLE DB error 0x80040E09 (The EXECUTE permission was denied on the object 'sp_ssis_listpackages', database 'msdb', schema 'dbo'.) occurred while enumerating packages. A SQL statement was issued and failed.
BUTTONS:
OK
So what do I do? How do I essentially run this as an administrator to get past this stupid elevated rights security error?
You should add your windows / sql account to sysadmin role.
In SQL Server Management Studio, go to Security -> Server Roles and double click sysadmin. Add your login and it should work when you try again.

"No backupset selected to be restored" SQL Server 2012

I have a SQL Server 2012 database with filestream enabled. However, when I backup it and try to restore it on another SQL Server 2012 instance (on another machine), I simply get this message that:
No backupset selected to be restored.
Not even a single line of more explanation. What's wrong here?
Every other database without filestream is OK and can be restored successfully. Is it something related to filestream? Should I install a hotfix or something like that.
I had this problem and it turned out I was trying to restore to the wrong version of SQL. If you want more information on what's going on, try restoring the database using the following SQL:
RESTORE DATABASE <YourDatabase>
FROM DISK='<the path to your backup file>\<YourDatabase>.bak'
That should give you the error message that you need to debug this.
My problem ended up being permissions. I'm on a dev machine and copied via Homegroup. Somehow, probably based on where I copied the file to, the permissions got messed up and Management Studio couldn't read the file. Since this is dev I just gave Everyone permissions to the bak file and could then successfully restore via the GUI.
When running:
RESTORE DATABASE <YourDatabase>
FROM DISK='<the path to your backup file>\<YourDatabase>.bak'
It gave me the following error:
The media family on device 'C:\NorthwindDB.bak' is incorrectly formed. SQL Server cannot process this media family. RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3241)
Blockquote
Turns out You cannot take a DB from a Higher SQL version to a lower one, even if the compatibility level is the same on both source and destination DB.
To check the SQL version run:
Select ##Version
To see the difference, just create a DB on your source SQL server and try to do a restore from your backup file, when you do this whit SSMS, once you pick the backup file it will show some info about it as opossed to when you open it from a lower version server that will just say "no backupset selected to be restored"
So if You still need to move your data to a lower version SQL then check This.
Run SQL Server Management Studio as an administrator (right-click the shortcut/exe, then select "Run as Administrator"), then try to restore.
I thought I was not stupid enough to mix up the versions - however, I didn't realize that on my new server, a SQL Server 2005 instance was already installed from birth named SQLEXPRESS. When trying to restore my SQL Server 2008 R2 backed up database in SSMS 2012 to the SQLEXPRESS instance, the list of backup sets was empty.
Eventually I realized that the SQLEXPRESS instance on the server was not a 2012 instance, but a 2005. I disconnected and connected to the actual 2012 instance (in my case named SQLEXPRESS2012), and it (obviously) worked.
My problem was that my user was in the Builtin-Administrators group and no user with Sysadmin-role on SQL Server.
I just started the Management Studio as Administrator. This way it was possible to restore the database.
FYI: I found that when restoring, I needed to use the same (SQL User) credentials to login to SSMS. I had first tried the restore using a Windows Authentication account.
In my case, it was permissions and the fact that I used "Restore Files and Filegroups..." rather than simply "Restore Database ...".
That made the difference.
For me it's a user privilege issue.
I logged-in with sa user and its working fine.
For me the problem was having the .BAK file located in an encrypted folder on the server. Even with full Admin rights, I could never get SSMS to read the file. Moving the .BAK to an unencrypted folder solved my problem. Note that after moving the file you may have to also change the properties on the actual file to remove encryption (right click, properties, advanced, uncheck "encrypt contents to secure data".
In my case (new sql server install, newly created user) my user simply didn't have the necessary permission. I logged to the Management Studio as sa, then went to Security/Logins, right-click my username, Properties, then in the Server Roles section I checked sysadmin.
I had the same issue with SQL Server 2014 (Management Studio could not see the folder in which the backup file resided, when attempting to locate it for a Restore operation). This thread held the answer that solved my problem. Quote:
The SQL Server service account can be found by Start->Control
Panel->Administrative Tools->Services. Double-click on the SQL Server
service->Log On tab. You'll either be using the "Local System account"
or "This account" to define a specific account. If you are using the
Local System account, you won't be able to reference backups that are
not local to the server. If, instead, you have defined the account to
use, this is the account that needs to have access to the backup file
location. Your ability to access the backups using your personal logon
is irrelevant; it is the SQL Server account that is used, even though
you are initiating the backup. Your IT people should be able to
determine what rights are granted to each account.
Hope that helps someone.
For me, it was because the backup file was still open by another process. Here's the event log:
BackupDiskFile::OpenMedia: Backup device 'X:\Backups\MyDatabase\MyDatabase_backup_2014_08_22_132234_8270986.bak' failed to open. Operating system error 32(The process cannot access the file because it is being used by another process.).
Simply closing and reopening Sql Server Management Studio resolved it (so obviously it was ssms.exe that had the handle..)
In my case, it was a permissions issue.
For the Windows user, I was using did not have dbcreator role.
So I followed the below steps
Connect as sa to the SQL server
Expand Security in Object Explorer
Expand Logins
Right click on the Windows user in question
Click on Properties
Select Server Roles from Select a page options
Check dbcreator role for the user
Click OK
Another potential reason for this glitch appears to be Google Drive. Google Drive is compressing bak files or something, so if you want to transfer a database backup via Google Drive, it appears you must zip it first.
If you want to replace the existing database completely use the WITH REPLACE option:
RESTORE DATABASE <YourDatabase>
FROM DISK='<the path to your backup file>\<YourDatabase>.bak'
WITH REPLACE
Using SQL Server 2012 Express.
My error (from the SQL Manager - Restore Database Dialog):
No backupset selected to be restored
Further, there were no backupsets shown in the list to select.
The issue was that I had moved 1 of the 5 backup files to a folder where the SQL Server service logon user did not have permissions - I tried to add that user, but could not get the NT Service\MSSQL$SQLEXPRESS user into the security list.
I moved the file under the Documents folder for the service user, and that enabled it to read all the files I had selected - 4 at that point - and the error changed to "media set missing" - then I looked around for another backup file, and when I added that I was able to restore.
The answers in this question helped me look in the right places and work my way to a solution.
For me, It was a permission issue. I installed SQL server using a local user account and before joining my companies domain. Later on , I tried to restore a database using my domain account which doesn't have the permissions needed to restore SQL server databases. You need to fix the permission for your domain account and give it system admin permission on the SQL server instance you have.
I got the same error message even though I backup and restore on the same single machine.
The issue was from here: when backup, i had 2 item in the destination box.
So the fix would be: make sure only 1 item in the 'destination' box. Remove all the others if there are.
I have run into the same issue. Run SSMS as administrator then right click and do database restore. Should work.
I think I get the award for the most bone headed reason to get this error. In the Restore Database dialog, the database dropdown under Source is gray and I thought it was disabled. I skipped down to the database dropdown under Destination thinking it was the source and made a selection. Doing this will cause this error message to be displayed.

SQL Server Management Studio: Database Attachment Failed

I have publish my website in IIS7. It is running in DefaultAppPool. The Identity of this app-pool is set to LocalSystem. The IIS is running and I can run the application from IIS without any problem.
Now I want to attach the database placed in inetpub's application folder:
C:\inetpub\wwwroot\EMSApplication\App_Data\ASPNETDB.mdf
I have added new logins in the SSMS which are: NT AUTHORITY\NETWORK SERVICE and IIS APPPOOL\DefaultAppPool.
But when I am trying to attach that database in the SSMS I am getting follwoing error:
TITLE: Microsoft SQL Server Management Studio
Failed to retrieve data for this request.
(Microsoft.SqlServer.Management.Sdk.Sfc)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&LinkId=20476
------------------------------ ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or
batch. (Microsoft.SqlServer.ConnectionInfo)
CREATE FILE encountered operating system error 5(Access is denied.)
while attempting to open or create the physical file
'C:\inetpub\wwwroot\EMSApplication\App_Data\ASPNETDB.MDF'. (Microsoft
SQL Server, Error: 5123)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.00.5500&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476
------------------------------ BUTTONS:
OK
By default Microsoft SQL Server Management Studio works against a Parent Instance of SQL Express, not your User Instance. A user instance is a separate instance of the SQL Server Express Database Engine that is generated by a parent instance. User instances allow users who are not administrators on their local computers to attach and connect to SQL Server Express databases. Each instance runs under the security context of the individual user, on a one-instance-per-user basis. Here is a manual from msdn How to connect to a User Instance.
I was able to do that running Management Studio As Administrator.
I had same problem.your .mdf and .ldf files don't have necessary permission.
you should add your windows account in both .mdf and .ldf files and give it full control permission.
Now you can attach your database successfully.

Resources