How can we get the attached file name (Attach As) from mdf or ldf file in SQL Server
Keep in mind, that we want get this name before attaching a file name to SQL Server Instance
[moved from answer]
now when you attach this database
EXEC sp_attach_db @dbname = N'PUBLISHER',
@filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf',
@filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf'
here PUBLISHER will be name that will display in the SQL Server Databases List
Now, at the time, I Detached the Database.
and when i Attach the Database, I don't want the Name, SQL Server must automatically picks the Last Name 'PUBLISHER' from file,
as when we attach the database by using SQL Server Management Studio Express,
as we right click on Databases --> Attach
A Dialog Appears
Here i browse the mdf file, SQL SErver automatilly gets the name PUBLISHER in attach as field, How I get this using VB.net or By using
[/moved from answer]