Click here to Skip to main content
15,887,966 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Can i get Database object from mdf file, like we use in SMO.

Database db=new DatbaseFromFile("abc.mdf"); // something like that (i m using c#)
Posted
Comments
Sandeep Mewara 20-Feb-13 9:11am    
What for? What exactly you are trying and want to do?
footballpardeep 20-Feb-13 9:22am    
From this object i want transverse th ewhole database details, like all tables,rows in each table etc. (i see something like this by using SMO but that was for database on sqlserver management studio, but i want through .mdf file)

1 solution

Have a look at this page in Connectionstring.com it shows how to attach a database through the connection string. Look for the headings "Attach a database file on connect to a local SQL Server Express instance"

www.Connectionstrings.com[^]
 
Share this answer
 
Comments
footballpardeep 20-Feb-13 9:14am    
Thanks for the link, i like that(this will help me later.)

But i want an Database object from mdf file. so that i can futher work on like this:
Tables tables=database.ALLTables();

Basically i want get the detail of database, like tables and after that transversing rows of table using this object.
Simon_Whale 20-Feb-13 9:20am    
a good starter might be using the sp_tables stored procedure

http://msdn.microsoft.com/en-us/library/ms186250(v=sql.100).aspx

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