Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to generate script of database with schema and data using c#. I am able to get the script for individual portions like table , storedProcedure ... but it is not a good way.

Can anyone please suggest a good method for doing it.

Thanks.
Posted
Comments
joshrduncan2012 16-Aug-13 9:56am    
What do you mean by "not a good way"?
Ariana Bond 16-Aug-13 10:00am    
I mean if i am getting scripts of individuals then obviously i have to merge it into one file which will consume some resources. I would like it in the way, a single file is generated.

1 solution

Refer - SMO scripting entire database like Studio Management does with Generate Scripts[^].
Quote:

Have a look at http://scriptdb.codeplex.com.
This is a tool that scripts out a Database's ddl.

For Scrripting out the data you could try an approach like described here: http://sqlblog.com/blogs/ben_miller/archive/2007/10/18/scripting-tables-views-and-data-using-smo-part-3.aspx or try to use bcp, wich would be the better alternative for bigger databases.

 
Share this answer
 
Comments
Ariana Bond 16-Aug-13 10:52am    
I would like to have my program rather to use free tool.
fjdiewornncalwe 16-Aug-13 12:10pm    
Then you can download the source from codeplex and figure out how it was done and implement it on your own.
Ariana Bond 16-Aug-13 12:27pm    
Hi Marcus,
I am getting this error when tried to script all objects.
Cannot script the object with Urn='Server[@Name='Example']/Database[@Name='DatabaseName']/ServiceBroker'.
If you have any idea then please help me.
fjdiewornncalwe 16-Aug-13 12:43pm    
Basically telling us "It doesn't work" doesn't really provide any information that we can help you with.
You'll have to use your debugger to step through the code and find where the code fails.
Ariana Bond 16-Aug-13 12:51pm    
I am creating alist of URN's while scripting the objects , but when Service Broker turn comes scripter.script () method throws exception "Failed Operation Exception".

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