Skip to main content

Posts

Showing posts with the label Using OLE functions

SQL server database size, location and volume info

For one of my clients, I needed to know and document not only database names, size and locations but also disk volume information as well. Now there is an easier way to get the same info using a DMV. https://sqlpal.blogspot.com/2018/04/get-sql-server-database-size-location.html Here is another way to retrieve same information using OLE functions. -- SQL SERVER VERSION 2005 & UP /* Caveat: This relies on OLE functions, if that option is not enalbed (which is default) it will try to enable it */ SET NOCOUNT ON -- if OLE automation is not enabled, execute the following code to enable it -- Enabling Ole Automation Procedures exec sp_configure 'show advanced options', 1; GO RECONFIGURE; GO exec sp_configure 'Ole Automation Procedures', 1; GO RECONFIGURE; GO SET NOCOUNT ON DECLARE @SQL VARCHAR(8000) DECLARE @hr int, @fso int, @drive char(1), @odrive int, @TotalSize varchar(20), @FreeSize varchar(20), @VolumeName varchar(4000), @MB Numeric SET @MB = 1048576 IF OBJECT_ID(...