SQL Server 2005 backup restore failing (with folder permissions) - sql-server-2005

I am trying to restore a database (from file thedb.bak). I am using SQL Server Express edition 2005 on a Windows 7 Ultimate 64-bit machine.
When I try to restore I get 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 (x86)\Microsoft SQL Server\MSSQL.2\MSSQL\Thedb.MDF'. (Microsoft.SqlServer.Express.Smo)
My username (antoniocs) is an Administrator. I have edited the permissions in the folder (C:\Program Files (x86)\Microsoft SQL Server\MSSQL.2\MSSQL\) so that the user AntonioCS has full control.
I really need to restore this backup. What am I missing?
Note: I am using the Windows authentication to login. Should I try another user (the one I use is an administrator in the machine)?

The account running the SQL Server service requires permissions on that folder.
You may be connected to SQL Server, but actions are done in the service account context: not you.
Run services.msc from command line, see what account is used, permission this folder accordingly.

Do you have a database that uses Thedb.MDF? I ran into this error when I tried to restore a database over a file that SQL Server used. From the restore window, choose Options and change the path or the filename from the "Restore the database files as".

Related

Restore BacPac database backup in sql server 2014

I have database backup file with extension .bacpac so how can i restore it in sql server 2014 ?
Two options:
In SQL Server Management Studio, right-click on the Databases folder in the Object Explorer tree. Then click on "Import Data-tier application". The wizard will guide you through the process.
From the command line, run this command: "c:\program files (x86)\Microsoft sql server\120\dac\bin\sqlpackage.exe" /a:import /sf:"PATH_TO_YOUR_BACPAC_FILE" /tcs:"Data Source=YOUR_SERVER_NAME;Initial Catalog=NEW_DATABASE_NAME;Integrated Security=true"
Aside: Note that the example connection string in the command line option above assumes you're using Windows Authentication instead of SQL Server authentication to access the server.

SQL LocalDB - Cannot delete a DB when its files are deleted

How can I delete a SQL LocalDB database that has had its files delete?
Dropping the database yields this message:
Unable to open the physical file "C:\Users\Public\Documents\LocalDB.Tests.3d0d7339-7cf2-45fe-a83b-b5079112ab80.mdf". Operating system error 2: "2(The system cannot find the file specified.)".
File activation failure. The physical file name "C:\Users\Public\Documents\LocalDB.Tests.3d0d7339-7cf2-45fe-a83b-b5079112ab80_log.ldf" may be incorrect.
Running master.sp_databases actually doesn't show them, but the Management Studio does.
The problem is that you are trying to drop a database when the physical file has been deleted or couldn't be found.
To get around this you can detach the database. Detaching will drop the database without attempting to remove the file from the filesystem.
EXEC sp_detach_db 'My_Db'
I'm assuming you're using (localdb) bundled with SQL Server 2012.
If you're using SQL Server 2014, use (localdb)\MSSQLLocalDB in place of (localdb)\v11.0 below
Open a command prompt
Start the localDb instance if it is not already running: “C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqllocaldb.exe” start “v11.0″
Drop the localDb database by running the following command: “C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqlcmd” -S (localdb)\v11.0 -E -d master -Q “DROP DATABASE [myDatabase]”
You can stop the localDb service now: “C:\Program Files\Microsoft SQL Server\110\Tools\Binn\sqllocaldb.exe” stop “v11.0″
Source: http://kazimnami.azurewebsites.net/techblog/2013/02/27/delete-localdb-database-after-physical-files-have-been-deleted/

SQL Server 2012 installation Reporting Services Catalog error

I'm installing SQL Server 2012 at the moment and when I was about to run the installation, this error pops up:
On clicking the first failed test, which is "Reporting Services Catalog Database File Existence", this is what i get:
On clicking the second failed test, which is "Reporting Services Catalog Temporary Database File Existence", this is what i get:
So basically, both of the message box says me that "Catalog Database File" & "Catalog Temporary database files exists". Because of this, i need to select Reporting Services file-only mode installation.
My questions are:
How do i select file-only mode installation?
Do i've to close the setup and do something and afterwards run the setup again?
Btw, I had SQL Server 2012 installed before. I uninstalled it completely due to some strange errors and decided to reinstall a fresh copy of SQL Server 2012 and now I'm stuck with these errors. Any help will be sincerely appreciated. :)
Since you already had one installation of SQL Server done before, there was a database already created. That did not get removed. So when you reinstall, its trying to create the database with the same name, hence, the error. You need to delete the old files to continue the new installation.
From the direcotry
C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
Remove the following files
ReportServer.mdf
ReportServer_log.LDF
ReportServerTempDB.mdf
ReportServerTempDB_log.LDF
Try the Following link for further help.
Reporting Services Catalog Error.
For sql-server-2012 the path is:
C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQL2012\MSSQL\DATA
where MSSQL2012 is the instance name and the respective file names are:
ReportServer$MSSQL2012.mdf
ReportServer$MSSQL2012_log.mdf
ReportServer$MSSQL2012TempDB.mdf
ReportServer$MSSQL2012TempDB_log.mdf
Remove the following files from the C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA directory:
bulletReportServer.mdf
bulletReportServer_log.LDF
bulletReportServerTempDB.mdf
bulletReportServerTempDB_log.LDF.
This happens if you reinstall SQL Server and these files weren't deleted.

Unable to connect to SQL Server 2008 R2

I am unable to connect to a local SQL Server 2008 R2 trial version from Visual Studio 2010 Express.
When adding a new connection, I browse to the database file in this location:C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks_Data.mdf, I encounter this error:
Could not open new data base 'C:\PROGRAM FILES\MICROSOFT SQL
SERVER\MSSQL10_50.SQLEXPRESS\MSSQL\DATA
ADVENTUREWORKS_DATA.MDF'.CREATE DATABASE is aborted. An attempt to
attach an auto-named database for file C:\Program Files\Microsoft SQL
Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA AdventureWorks_Data.mdf
failed. A database with the same name exists, or specified file cannot
be opened, or it is located on UNC share. File activation failure.The
physical file name "C:\Program Files\Microsoft SQL
Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks_Data_log.ldf"
may be incorrect.
The log cannot be rebuilt when the primary file is read-only.
Another guess, you don't by any random chance have another user logged into the same machine that would have the DB file locked by connecting to it in the same way you say you're trying to? I'd imagine the previous comment about that database file already being attached to by the sql service is probably far far more likely, but just for wild chance I'm leaving my idea here for you or anyone else who happens by

sp_attach_single_file_db Error: failed with the operating system error 5(Access is denied.)

I'm trying to use this DataBase that come with this sample project with from MS:
http://code.msdn.microsoft.com/ASPNET-Web-Forms-6c7197aa/sourcecode?fileId=18930&pathId=365206059
So after I downloaded the files: I need to attach the .mdf DataBase to my Instance of MS SQL 2008.
From Management Studio Attaching DataBase does not work and event using this command i receive the same error:
sp_attach_single_file_db 'School.mdf', 'C:\School.mdf'
ERROR:
Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "C:\School.mdf" failed with the operating system error 5(Access is denied.).
Any idea what is wrong? Thanks for your help!
Give full permission on folder in which you want to create the mdf file
to the logon account with which the SQL Server service is running.
Usually: NT Service\MSSQL$
You can look that up
Control Panel-> Administrative Tools-> Services=> SQL Server -> Prperties-> Logon Tab-> Note the account
What operating system are you running on? Did you get an elevation prompt when you saved the file to the root of the C drive? What user account is SQL Server running under, and does it have permissions to read any files in the root of the C drive?
You might do better placing the file into %ProgramFiles%\Microsoft SQL Server\MSSQL10.<instance name>\MSSQL\DATA, alongside the other .mdf files that you know it can already read (adjust path above as necessary, but you hopefully get the idea).
I had this issue and all the solutions online was misleading.
The solution was to open SSMS as Administrator. In my opinion first try this and later try all other solutions.
Moving it to DATA folder basically resolved permission issue. Another solution is to change the permissions of the file (or files) and thus still have DB in different folder. I just ran into similar permission error "CREATE FILE encountered operating system error 5(Access is denied.)" trying to attach DB in SQL Server 2012 express on Windows 7.
Solution I did was following:
1) Rich-click on each MDF, LDF, and NDF file to get menu --> select properties
2) Add Users for computer and give them full control (instead of Everyone - to dangerous)
After that I could attach the DB.
However, even if not moved to DATA folder, should move into subfolder instead of C:\ root (example: C:\mydb).
create DATABASE newDataBaseName
on (FILENAME = 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\filename.mdf'),
(FILENAME = 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA\filename_log.ldf')
FOR ATTACH_REBUILD_LOG;
GO
Also as Damien mentioned above put the mdf files in the where your other mdf files are located. For me C:\Program Files (x86)\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA
In my case I found the Directory lookup needed the computer/users group in read/list permissions. While the service and the actual user running the (in my case) restore had full permissions that permission was important.
Security wise I hate it.