I simply want to use program to read database structure (schema) and save it into a file to be used to recreate DB structure

I am using asp.net c# and Microsoft SQL

Really my request is quite simple to be able to read database structure, ie tables and relations and stored procedures etc. and store it in a file.  So later I could execute the file and recreate the db in its entirety.  Not talking about data.
goodkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
You can do all those from SSMS , you can right click the database you want to script , choose all the objects and generate the script
0
Scott PletcherSenior DBACommented:
Unfortunately it's not quite that simple.  There are LOTS of options that control the scripting.  You need to go thru all those options and verify that everything you need will be scripted.

Honestly, if the data isn't large, it'd be easier and probably more accurate to restore the entire db, and then truncate/delete table data.
0
goodkAuthor Commented:
I am amazed that it is such a universal issue and no one has a generalized program to save the database structure in a file.  

I am also wondering if there is a way to execute the SSMS script which saves the database via program?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

goodkAuthor Commented:
Also, one more problem as I am using shared database it will not let me run SSMS scripts to save the file - so program is the only choice
0
Randy Knight, MCMPrincipal ConsultantCommented:
There is commercial 3rd party software to do what you're looking for but nothing free that I'm aware of, other than the manual scripting out of the database using SSMS as mentioned above.

If you really want to do this from code, you need to take a look at SQL-SMO.  That is the object model that you can use from .NET to do all kinds of things within SQL Server.  In fact it's what SSMS uses.

http://msdn.microsoft.com/en-us/library/ms162169.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
goodkAuthor Commented:
thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.