SQL Server database backup file (.bak ) file gets corrupted - sql

I have been working on a SQL Server database designing since long now and I have observed that when a .bak file is mailed or kept and downloaded from ftp site, it gets corrupted.
When I try to restore, it gives me 3013 error code with messsage:
"Backup or restore operation terminating abnormally.
I tried RESTORE VERIFYONLY FROM DISK='C:\abc.bak' as well but it says
VERIFY DATABASE is terminating abnormally.
Any idea why this is happening and also, is there a better way to move the database file from one server to another (I do not have the access to source server)
Thanks in advance.

For FTP make sure that you use binary mode.
Did you try to send plain attachment to yourself and compare the results with the files from sent and received email?

As mentioned here
You may need to repair your mdf file first using some tools. There are lot of tool available in the market. There is tool called Restore MS SQL Database which is very useful to repair the mdf files.
The issue might me because of corrupted transaction logs, you may use tool Restore MS SQL Database to repair your corrupted mdf file.

Related

Corrupting a database backup to fail CHECKSUM

I'm currently setting up the monitoring for some SQL servers running on windows and I want to test if it picks up any errors that occur when backups fail. I'm using the CHECKSUM option for backup validation.
Is it possible to corrupt the backup in a way so that the CHECKSUM validation fails?
CHECKSUM verifies the file is not corrupt in the same RESTORE or BACKUP command; can also be set at a database-level so it always runs a self-check. I don't know of a way to intentionally cause this to fail during a BACKUP command, unless you're corrupting it on the I/O level outside of SQL Server.
RESTORE HEADERONLY verifies the file can be restored completely; this can be performed any time after the backup has completed. Essentially, fake-attempts a full restore to ensure the file is a legit backup. More info here.

is it possible to open a .bak file in sql without connecting to a database?

i have a .bak file and i want to check its data before importing it to host ! i tried to open it with MS SQL server management studio to see data inside the backup file. i googled a lot but i couldnt understand how to open this file ! i saw every solution to import a .bak file in a existed database ! i have no database on my local computer. how can i check my backup file data ? anyone can help ?
thanks in advance !
There are some 3rd party tools. Try searching google for "open bak file without sql server".
Also there is free SQL express, so you can install server on your local computer and attach database. Default installation should do the trick.
You can even open it in notepad, but it's not very practical..

sql server 2005 (for old systems) and many problems for attach and restore...(changing drive location)

why sql server 2005 so sucks?
i should work on an old system that using sql server 2005!
my problems are :
1-when i detach a database and move mdf / ldf files of that db to another drive , so i can
not attach these files because of moving!
what is the best way for change the location of mdf/ldf files to another drive?
==============================================================================
2-when i backup a db that mdf/ldf of that db are on drive e , so i can not restore that bak file to another system that has not drive e / what is going on about sql server 2005 / i test this job on sql server 2008 and every thing was ok / how can i solve this issue?
i am using windows 7 ultimate / sql server management studio express edition /
thanks in future advance
best regards
When you restore a database backup you need to go into the restore options and update the paths of the MDF/LDF files to wherever you want them on the new machine. The default is to keep these paths the same and obviously they may not exist on the new machine.
When you did the restore, you pointed the data and log files to the new drives - you may have done this in the GUI (Management Studio) or in TSQL. When you try the reattach, you need to do the same thing - just change the file locations.
Firstly you take the backup of SQL database including Log transaction files also. Then detach it by right clicking on it. Now you can change the location of MDF file and then restore. it.

Error opening .mdf file through SQL Server Management Studio Express

I am doing a project of a web enabled database. I have created the database file in my PC.
Now when I just want to open .mdf i.e. of the database I created, I cannot open it in other PC. I even had copied the .ldf file i.e the log file to that PC.
Since I need to transfer the database to the Server later, I don't know how I will dump the database in that server from my PC so that the company can use it.
The basics of using mdf file is like this:
Create a new database using SQL Server (set the path for the file as you wish)
If you wish to move the file elsewhere,
detach the database from your server
copy/move the file to wherever you wish
attach the file as database in SQL server
You are not supposed to open the file by double-clicking as mime setting or attachment of extensions migh not be there in the target machine.
Why don't you use the decent method to copy/move database?

Locked SQL Server Data Files

I have an SQL Server database where I have the data and log files stored on an external USB drive. I switch the external drive between my main development machine in my office and my laptop when not in my office. I am trying to use sp_detach_db and sp_attach_db when moving between desktop and laptop machines. I find that this works OK on the desktop - I can detach and reattach the database there no problems. But on the laptop I cannot reattach the database (the database was actually originally created on the laptop and the first detach happened there). When I try to reattach on the laptop I get the following error:
Unable to open the physical file "p:\SQLData\AppManager.mdf". Operating system error 5: "5(error not found)"
I find a lot of references to this error all stating that it is a permissions issue. So I went down this path and made sure that the SQL Server service account has appropriate permissions. I have also created a new database on this same path and been able to succesfully detach and reattach it. So I am confident permissions is not the issue.
Further investigation reveals that I cannot rename, copy or move the data files as Windows thinks they are locked - even when the SQL Server service is stopped. Process Explorer does not show up any process locking the files.
How can I find out what is locking the files and unlock them.
I have verified that the databases do not show up in SSMS - so SQL Server does not still think they exist.
Update 18/09/2008
I have tried all of the suggested answers to date with no success. However trying these suggestions has helped to clarify the situation. I can verify the following:
I can successfully detach and reattach the database only when the external drive is attached to the server that a copy of the database is restored to - effectively the server where the database is "created" - lets call this the "Source Server".
I can move, copy or rename the data and log files, after detaching the database, while the external drive is still attached to the Source Server.
As soon as I move the external drive to another machine the data and log files are "locked", although the 2 tools that I have tried - Process Explorer and Unlocker, both find no locking handles attached to the files.
NB. After detaching the database I tried both stopping the SQL Server service and shutting down the Source Server prior to moving the external drive - still with no success.
So at this stage all that I can do to move data between desktop and laptop is to make a backup of the data onto the external drive, move the external drive, restore the data from the backup. Works OK but takes a bit more time as the database is a reasonable size (1gb). Anyway this is the only choice I have at this stage even though I was trying to avoid having to go down this path.
Crazy as it sounds, did you try manually granting yourself perms on the files via right-click / properties / security? I think SQL Server 2005 will set permissions on a detached file exclusively to the principal that did the detach (maybe your account, maybe the account under which the SQL Server service runs) and no-one else can manipulate the file. To get around this I have had to manually grant myself file permissions on MDF and LDF files before moving or deleting them. See also blog post at onupdatecascade.com
Can you copy the files? I'd be curious to know if you can copy the files to your laptop and then attach them there. I would guess it is some kind of permissions error also, but it sounds like you've done the work to fix this.
Are there any attributes on the file?
Update: If you can't copy the files then something must be locking them. I would check out Unlocker which I haven't tried but sounds like a good starting point. You might also try taking ownership of the files under the file permissions.
When you are in Enterprise Manager or SSMS, can you see the name of the database that you are talking about? There might be a leftover database in a funky state. I'd make sure that you have a backup or a copy of the mdf somewhere safe. If this is the case, maybe try dropping the database and then re-attaching it.
I would try backing up the database on the desktop, and then see if it will restore successfully on the laptop. Doesn't explain your issue but at least you can move forward.
Run sqlservr.exe in debug mode with the /c switch and see what happens starting up. Any locking or permissions issue can be put to bed by making a copy of the file and transfering the copy to the origional.
Also check the associated log file (.ldf) .. If that file is missing or unavaliable you will not be able to mount the database to any sane/consistant state without resorting to emergency bypass mode.
I've had a similar issue. Nothing seemed to resolve it - even tried to reboot the machine completely, restarting SQL services etc. ProcMon and ProcessExplorer were showing nothing so I figured - the "lock" is done by OS.
I resolved it by DELETING the file and restoring it back from the drive mounted under another drive letter.
PS. My database file was not on a USB drive, but on a TrueCrypt-drive (in some you can say it's a "removable drive" as well)
Within SQL Server Configuration Manager, look in SQL Server Services. For all your SQL Server instances, look at which account is selected in the Log On Tab - Log On As:. I've found for instance, changing it to the Local System account resolves the issue you've had. It was the only thing that actually worked for me - and certainly, no shortage of people have had the same problem.
It's a security issue on -file level security - you have detached db with different credential and attaching it with other credential - just browse the article http://www.sqlservermanagementstudio.net/2013/12/troubleshooting-with-attaching-and.html
And try copy pasting it to different location.
I solved similar issue by granting system administrator to all permissions:
right click > properties
security tab
in group or usernames click edit.
click add > advanced
click find now to list all available permissions.
choose administrator and add it to list.
grant it to has full permission.
I had the same issue. Someone had detached the files and left, and we were unable to move it to another drive. But after taking ownership of the file (security-->advanced-->take ownership to your login id), and then adding your login id to the security tab and giving access on the file, was able to move.