I'm writing a C# application which downloads a compressed database backup via FTP. The application then needs to extract the backup and restore it to the default database location.
Since I won't know what version of SQL will be installed on the machine where the application runs, I need to be able to find the default location based on the instance name (which is in the config file).
The examples I found all had a registry key which they read, but this won't work, since this assumes that only one instance of SQL is installed.
Another expample, created a database, and then read that database's file properties, before deleting the database again. That's just cumbersome,
I did find something in the .NET framework which should work, ie:
Microsoft.SqlServer.Management.Smo.Server(ServerName).Settings.DefaultFile
The problem is that this is returning empty strings, which does not help.
I also need to find out the NT account under which the SQL service is running, so that I can grant read access to that user on the backup file once I have the it extracted.