How to complete removal of filestream and all attached files

I tried the FILESTREAM function for MSSQL (2008R2 Data Center) on a local database to experiment. The real database runs on a server. I installed the whole FILESTREAM using this request:

/* CREATE FILESTREAM AND FILESTREAM TABLE */
USE [master]
GO
ALTER DATABASE SenONew
ADD FILEGROUP [FileStream]
CONTAINS FILESTREAM
GO
ALTER DATABASE SenONew
ADD FILE
(
NAME = 'fsSenONew',
FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\SenONew.ndf'
)
TO FILEGROUP [FileStream]
GO

USE [SenONew]
GO
CREATE TABLE Filestore(
    FileID int PRIMARY KEY,
    RowID uniqueidentifier ROWGUIDCOL NOT NULL UNIQUE DEFAULT NEWSEQUENTIALID(),
    FileDescr nvarchar(max),
    FileIndex varbinary(max) FILESTREAM NULL)
GO

      

And I experimented with adding multiple files and then deleting them.

Now, since this was just an experiment, I also want to get rid of it. I am using my local server to develop a database to be used on the real server, so I create a BackUp on my local server and then restore this to the real server, so it gets updated (the software is in development, so the database structure changes like this the same as the data, and I need to do a full restore on the real server on which the software is being tested).

After hours of searching, I couldn't find anything for my problem.

I understand what I need:

  • Remove database table storing FILESTREAM information
  • I need to delete FILESTREAM FILE
  • Delete filegroup

So, I use this query to get rid of everything I configured in the first place:

/* DROP FILESTREAM TABLE AND FILEGROUP */
USE SenONew
DROP TABLE Filestore
GO

ALTER DATABASE SenONew
REMOVE FILE fsSenONew

ALTER DATABASE SenONew
REMOVE FILEGROUP [FileStream]
GO

      

So, I do whatever I should and it exits without error. So when I go into my filegroups, files and file locations, I see that they are completely removed:

enter image description hereenter image description hereenter image description here

But when I BACKUP my local database (including the remote FILESTREAM, filepath and filegroup) and try to restore the server with it, I get errors.

SQL to create BACKUP:

/* CREATE BACKUP OF DATABASE WITHIN CURRECT CONNECTION */
DECLARE @FileName2 nvarchar(250)
SELECT @FileName2 = (SELECT 'C:\SenO BackUp\' + convert(nvarchar(200),GetDate(),112) + ' SenONew.BAK')
BACKUP DATABASE SenONew TO DISK=@FileName2
GO

      

enter image description here

Then perform a server restore:

/* CREATE RESTORE OF DATABASE WITHIN REAL SERVER CONNECTION */
use master
alter database SenONew set offline with rollback immediate;

DECLARE @FileName2 nvarchar(250)
SELECT @FileName2 = (SELECT '' + convert(nvarchar(200),GetDate(),112) + ' SenONew.BAK')
RESTORE DATABASE SenONew
FROM DISK = @FileName2

alter database SenONew set online with rollback immediate;

      

I am getting the following error:

enter image description here

* (Msg 5121, Level 16, State 2, Line 7 The path specified in "C: \ Program Files \ Microsoft SQL Server \ MSSQL10_50.SQLEXPRESS \ MSSQL \ DATA \ SenONew.ndf" is not in a valid directory.

Msg 3156, Level 16, State 3, Line 7 The file 'fsSenONew' cannot be restored to 'C: \ Program Files \ Microsoft SQL Server \ MSSQL10_50.SQLEXPRESS \ MSSQL \ DATA \ SenONew.ndf'. Use WITH MOVE to determine a valid file location.

Msg 3119, Level 16, State 1, Line 7 Problems were identified while scheduling the RESTORE statement. Previous posts provide detailed information.

Msg 3013, Level 16, State 1, Line 7 DATABASE RESTORE terminates abnormally. ) *

I removed the .ndf FILESTREAM location, why is this the given path? Also, why is fsSenONew trying to recover? I cannot think it over. Are there internal paths that I need to remove?

+3


source to share


1 answer


You can check:

SELECT * FROM SenONew.sys.data_spaces WHERE name = 'FileStream' 

      

it should return 0 lines.

There is a procedure to remove FILESTREAM functions from a SQL Server 2008 database:

ALTER TABLE Filestore DROP column FileIndex
GO
ALTER TABLE Filestore SET (FILESTREAM_ON="NULL")
GO
ALTER Database SenONew REMOVE FILE fsSenONew
GO
ALTER Database SenONew REMOVE FILEGROUP [FileStream]
GO

      

as described in this article . But the steps you took should do the same.



Your problem is of course weird, but I suggest you try using the following

USE SenONew
EXEC Sp_help 
EXEC Sp_helpfile 
EXEC Sp_helpfilegroup 

      

You can find something fishy in there like another table using this FILEGROUP.

I have followed exactly the steps you are describing and cannot reproduce your problem. Check what the recovery database screen looks like.

enter image description here

+3


source







All Articles