Hello, I'm using NHibernate for a project. This project opens a SQL Server 2005 database and then, after all work is done, It's supposed to backup the database. The problem is that SQL Server keeps the handle open after calling factory.Close(), so the backup copy fails. How do I close the file handle? Thanks in advance.
+2
A:
If you are trying to make a copy of the database file you can take the database offline.
ALTER DATABASE AdventureWorks SET OFFLINE
--Copy the data file
ALTER DATABASE AdventureWorks SET ONLINE
To take an online backup you can use the BACKUP DATABASE command.
BACKUP DATABASE AdventureWorks
TO DISK = 'Z:\SQLServerBackups\AdvWorksData.bak'
Rob Boek
2009-01-21 09:01:54
I'll agree and add: You backup MS SQL databases online using the BACKUP command. You don0t take it offline and copy it
gbn
2009-01-24 09:24:09
I agree, but wanted to make sure I answered his question which was how to close the file handle.
Rob Boek
2009-01-27 19:44:18