HuxleyKendell / AutoRodent

2 stars 0 forks source link

CreateAllFromBackup - Add logic to check for default Data/Log file locations #2

Open csnhawkins opened 4 months ago

csnhawkins commented 4 months ago

There's two schools of thoughts for this, one checks the registry and the other checks a location on the SQL Server (This is my preference). The logic is as follows:

DECLARE @mdfLocation nvarchar(256) = CAST(SERVERPROPERTY('InstanceDefaultDataPath') AS nvarchar(200)); DECLARE @ldfLocation nvarchar(256) = CAST(SERVERPROPERTY('InstanceDefaultLogPath') AS nvarchar(200));

Then all you need to do is update the SET logic to be as follows:

-- Define file paths for current database
SET @DataFilePath = @mdfLocation + @DatabaseName + '_Data.mdf'
SET @LogFilePath = @ldfLocation + @DatabaseName + '_Log.ldf'
HuxleyKendell commented 3 months ago

update

This is the potential fix? Going into repo!

HuxleyKendell commented 3 months ago

image

Works on current env