under MSSQL ATTACH DATABASE SQL there is a nice script to attach / detach a database on a MSSQL server. Is there any system variable in Delphi I can use to detect the path the the database files by source code ?
Asked
Active
Viewed 733 times
2 Answers
3
If you want to get path of a data file of a certain database, you'll need to query the sys.master_files
table. In its physical_name
column is stored the file name of a database data file, so running a query like this should give you what you need:
SELECT
physical_name
FROM
sys.master_files
WHERE
database_id = DB_ID(N'your_database_name')

TLama
- 75,147
- 17
- 214
- 392
-
I doubt that there is an entry for a file he wants to **attach** ;-). – alzaimar Mar 18 '13 at 10:34
-
1+1. I think it's obvious OP is looking for the `OriginalDB` path (the one that needs to be detach). – kobik Mar 18 '13 at 22:34
0
You can put your database file wherever you want (except network drives, of course), as long as the SQL-Server account has appropriate rights to the file.
In case you want to stick with the default settings, i.e. the default database location/path, see this article for details.