|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 8:27 AM
Points: 1,084,
Visits: 808
|
|
I'm struggling to find a way to get the default data and log locations using t-sql. Is there a way to either do this without reading the registry? if not, does anyone have a script that will grab those values from the registry regardless of default/named instance?
I have one that works well for default instance, but I need one I can drop on any server and have it grab those values correctly.
Any help would be greatly appreciated. Thanks
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, April 23, 2013 12:18 PM
Points: 1,103,
Visits: 1,781
|
|
Data:
-- *************************************************************************** -- nvarchar(4000) = dbo.fn_SQLServerDataDir() -- *************************************************************************** IF OBJECT_ID('SQLServerDataDir_fn','FN') IS NOT NULL DROP FUNCTION SQLServerDataDir_fn GO
create function dbo.SQLServerDataDir_fn() returns nvarchar(4000) as begin
declare @rc int, @dir nvarchar(4000) exec @rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\MSSQLServer',N'DefaultData', @dir output, 'no_output'
if (@dir is null) begin exec @rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\Setup',N'SQLDataRoot', @dir output, 'no_output' select @dir = @dir + N'\Data' end
return @dir
end
Log
-- *************************************************************************** -- nvarchar(4000) = dbo.SQLServerLogDir_fn() -- *************************************************************************** IF OBJECT_ID('SQLServerLogDir_fn','FN') IS NOT NULL DROP FUNCTION SQLServerLogDir_fn GO
create function dbo.SQLServerLogDir_fn() returns nvarchar(4000) as begin
declare @rc int, @dir nvarchar(4000)
exec @rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\MSSQLServer',N'DefaultLog', @dir output, 'no_output'
if (@dir is null) begin exec @rc = master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE',N'Software\Microsoft\MSSQLServer\Setup',N'SQLDataRoot', @dir output, 'no_output' select @dir = @dir + N'\Data' end
return @dir
end
--
|
|
|
|