Reputation: 2194
Is there a way to determine, given a drive and a directory, if a CREATE DATABASE
command would succeed? There are basically two questions here.
How do you determine if a simple command like this will succeed? Which directories will contain the mdf and ldf files, and can this be determined via query (say for a tool that creates databases and needs to provide a default directory that the user can choose to use)?
CREATE DATABASE v1rds
ON PRIMARY (NAME=N'v1rds' , FILENAME=N'v1rds.mdf')
LOG ON (NAME=N'v1rds_log' , FILENAME=N'v1rds_log.ldf')
If the user is allowed to enter a directory path into the database-creation tool, how can the directory path be validated? The command like this works in SQL Server but not in AWS RDS SQL Server:
SELECT FILE_EXISTS, FILE_IS_A_DIRECTORY, PARENT_DIRECTORY_EXISTS
FROM SYS.DM_OS_FILE_EXISTS('L:\LDF');
/****
Error message on AWS RDS SQL Server is:
Msg 229, Level 14, State 5, Line 1
The SELECT permission was denied on the object 'dm_os_file_exists', database 'mssqlsystemresource', schema 'sys'.
Completion time: 2024-02-20T14:29:26.6268208-05:00
****/
I do not know which permissions are required on the login that calls DM_OS_FILE_EXISTS
. Short of having to run the command as RDSA, which permissions or roles have to be granted to the login to make this work?
Upvotes: 0
Views: 89