0

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 ?

Community
  • 1
  • 1
user1769184
  • 1,571
  • 1
  • 19
  • 44

2 Answers2

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
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.

Community
  • 1
  • 1
alzaimar
  • 4,572
  • 1
  • 16
  • 30