943,667 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Marked Solved
  • Views: 11167
  • MS SQL RSS
Mar 4th, 2009
0

Could not continue scan with NOLOCK due to data movement

Expand Post »
Good Morning Friends,

I have a SP that is Supposed to Restore a Database from a Backup. In some Clients this works well but in those particular client its a Problem. The version is SQL 2005.

Here is the Code that fails
MS SQL Syntax (Toggle Plain Text)
  1. SET ANSI_NULLS ON
  2. SET QUOTED_IDENTIFIER ON
  3. go
  4.  
  5.  
  6.  
  7.  
  8. -- Restore a backed up database
  9. -- Given: the filename and path where the backedup database file is located and the name of the database to restore it as
  10. -- The entry will be restored and a row placed into oDirect.dbo.tbl_dbref - which keeps track of the databases
  11. -- The users for the database must also be restored!
  12. ALTER PROCEDURE [dbo].[sp_RestoreDatabase]
  13.  
  14. @dbname char(32), -- the database name to restore as
  15. @filename char(64), @path char(256) -- the location of the backuped up database file (on the SQL Server)
  16.  
  17. AS
  18.  
  19. SET nocount ON
  20.  
  21. declare @sql nvarchar(3000)
  22.  
  23. execute('sp_ClearDatabaseConnections ' + @dbname)
  24.  
  25. -- Restore the database
  26. SELECT @sql = ' RESTORE DATABASE ' + ltrim(rtrim( @dbname )) + ' FROM DISK = ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @filename )) + ''' '
  27. SELECT @sql = ltrim(rtrim(@sql)) + ' WITH RECOVERY, '
  28. SELECT @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + 'TNGoedit_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , ' -- logical file name to physical name
  29. SELECT @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + 'TNGoedit_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' ' -- logical file name to physical name
  30. --select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + ltrim(rtrim(@dbname)) + '_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , ' -- logical file name to physical name
  31. --select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + ltrim(rtrim(@dbname)) + '_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' ' -- logical file name to physical name
  32. print @sql
  33. execute ( @sql )
  34.  
  35. -- Was the command successful or was there a problem
  36. IF ( (SELECT @@Error) = 0 ) begin
  37. -- Put an entry into oDirect.dbo.tbl_dbRef
  38. -- execute ( 'sp_DataSet_Save ''' + @xml + ''' ' )
  39.  
  40. -- TODO: restore the users
  41.  
  42. SELECT 'Restore Successful' [Result]
  43. end
  44. else begin
  45. SELECT 'Restore Unsuccessful' [Result]
  46. end
  47.  
  48.  
  49. /* -- Example of a restore
  50. RESTORE FILELISTONLY
  51.   FROM DISK = 'C:\Inetpub\wwwroot\oBooking\Databases\oBookingMasterDB'
  52.  
  53. RESTORE DATABASE tst
  54.   FROM DISK = 'C:\Inetpub\wwwroot\oBooking\Databases\oBookingMasterDB'
  55.   WITH RECOVERY,
  56.   MOVE 'LBS_Data' TO 'C:\Inetpub\wwwroot\oBooking\Databases\tst.mdf', -- logical file name to physical name
  57.   MOVE 'LBS_Log' TO 'C:\Inetpub\wwwroot\oBooking\Databases\tst_log.ldf' -- logical file name to physical name
  58. */


And i get the Error

Quote ...
Exception caught in: ExecuteStoredProc: Could not continue scan with NOLOCK due to data movement. RESTORE could not start database 'Testv3'. RESTORE DATABASE is terminating abnormally. Database 'Testv3' cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.
Thank you.
Reputation Points: 31
Solved Threads: 14
Posting Whiz
vuyiswamb is offline Offline
310 posts
since Mar 2007
Mar 8th, 2009
0

Re: Could not continue scan with NOLOCK due to data movement

Looking at the error message about NOLOCK, I came across this article from Microsoft http://support.microsoft.com/kb/815008. But, this is for SQL Server 2000, which you said you are using 2005. Although, in the same article Microsoft said you can run this TRACE "DBCC TRACEON (9134, -1)" to ignore the row that has a lock on it. Not sure if this will help.
Reputation Points: 12
Solved Threads: 6
Junior Poster
Geek-Master is offline Offline
156 posts
since Dec 2004
Mar 12th, 2009
0

Re: Could not continue scan with NOLOCK due to data movement

Thank you very much for your help.

The Problem is that the Database that i wanted to restore from was Corrupt.

Thank you
Reputation Points: 31
Solved Threads: 14
Posting Whiz
vuyiswamb is offline Offline
310 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: subtract two column value
Next Thread in MS SQL Forum Timeline: Can SQL Server 2008 access Northwind or Pubs databases?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC