sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'

环境:windows 2016 + sqlserver 2017

备份时正常,还原时一直卡在下面的界面不动

sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'_第1张图片

 

查看日志发现两个报错

sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'_第2张图片

The operating system returned the error '21(设备未就绪。)' while attempting 'GetDiskFreeSpace' on 'Z:\'.

The operating system returned the error '21(设备未就绪。)' while attempting 'GetDiskFreeSpace' on 'A:\'.

 

查看发现A是软盘,Z是DVD驱动器,感觉还原应该不会用到这俩,不知道为啥报这种错

sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'_第3张图片

打开profile可以发现还原报错时有以下记录

sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'_第4张图片

所以这个报错应该跟sys.dm_os_enumerate_fixed_drives视图有关系

查询这个视图,会发现同样的报错

select * from sys.dm_os_enumerate_fixed_drives;

sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'_第5张图片

sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'_第6张图片

继续搜索发现sys.dm_os_enumerate_fixed_drives是sqlserver 2017新加的一个视图,用来替代原来的xp_fixeddrives获取空闲空间,所以这应该还是2017才会遇到的问题

 

解决方法:

法1. 禁用软盘和DVD驱动器

sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'_第7张图片

禁用之后可以看到查询视图不再报错

sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'_第8张图片

还原也能正常进行

sqlserver 2017 还原遇到报错The operating system returned the error '21(设备未就绪。)'_第9张图片

法2:禁用该新特性(不大推荐)

sp_configure 'show advanced options', 1; 
GO
RECONFIGURE;  
GO  
sp_configure 'SMO and DMO XPs', 0;  
GO  
RECONFIGURE  
GO

参考

https://blog.sqlauthority.com/2017/09/23/sql-server-operating-system-returned-error-21the-device-not-ready-attempting-getdiskfreespace/

http://www.dharmendrakeshari.com/sql-server-management-studio-v17-operating-system-returned-error-21/

https://www.mssqltips.com/sqlservertip/4933/sql-server-2017-restore-database-error-in-ssms/

https://support.microsoft.com/en-us/help/4046638/add-the-ability-to-disable-or-enable-few-new-dmvs-and-dmfs-introduced

你可能感兴趣的:(备份还原,sqlserver,新特性)