Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
SQL
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
Updated 18-May-12 7:08am
v2
Comments
Maciej Los 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?
Maciej Los 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900