Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Server
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 sp_attach_db Options
 
[/moved from answer]
Posted 16-May-12 21:07pm
Edited 18-May-12 7:08am
(no name)136.6K
v2
Comments
losmac at 18-May-12 7:03am
   
Not clear...
Do you want to know the name of each file attached to sql server or do you want to search for it?
losmac at 18-May-12 13:09pm
   
Always use "Improve question" button to update your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 18 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100