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.
I'm writing a SQL Server stored procedure to backup a database into a network shared location.
The command as follows: (whole D drive has been shared)
BACKUP DATABASE MyDB
TO DISK = '\\192.168.1.50\d\Backups\MyDb_20200615-09.54.08.BAK'
The command is working fine for a local path, but for the shared path, it throws the following error:
Operating system error 1909(The referenced account is currently locked out and may not be logged on to.).
How to get rid of this error?
Thanks in advance.
Yeah, longstanding issue- UNC paths are a big pain with SQL server commands, and often not usable at all. Two possibilities:
Drop the backup onto a local disk and then copy it to your network path.
Map the drive. Note that there are significant and painful access issues because most SQL Server instances run as local SYSTEM and won't have the ability to access network drives.
Edit: the permissions issue is the reason you’re getting locked out. The SYSTEM account credentials won’t work on other machines. You need to create an account with matching credentials on both machines and run the SQL server instance as that account. This can have other implications. It’s easier (and possibly safer) to drop the backup to local disk and copy it with script credentials.
I have a primary SQL Server where backup job is running every night and backup gets stored in local drive.I want to copy that backup and store that in my fail-over SQL Server.
Options I tried:
I created a backup job to save that backup to my fail-over server drive, but I get an error "access is denied for the \xxx.xx.xxx\D$\backup path"
Is there a script to copy the backup and save it in another server drive?
Please see the screenshot
I have seen some post relating to this topic, but there is no accepted answer.
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.
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.