I want to be able to create a database within my C# WinForm application using the code I found HERE.
But I need to find a way to get the default data directory for that particular SQL Server Instance. I am wondering if there was a easy way to accomplish this that is able to be used on the various versions of SQL Server.
Thanks in advance.
EDIT
I found the following Select that will return the default data directory on the remote server:
SELECT
SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
FROM master.sys.master_files
WHERE database_id = 1
AND file_id = 1
This solution will only work on SQL Server 2005+.
**