Hi,
I want to generate a database script for all tables only same as we do it in SQL Management Studio manually using SMO in C#.
Thanks
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 8, 2009, 5:06 PM EST
Here is your Solution .
Just Run Following Commands Programatically . and it will Create the Script Files .
private void button1_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = @"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz";
p.StartInfo.Arguments= @"script -d AdventureWorks "C:\AdventureWorks.sql";
p.Start();
}
Other commands wich will helps you ,are below just Execute it like above :)
Command to run which will create schema and database:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks "C:\AdventureWorks.sql"
Command to run which will create schema:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks "C:\AdventureWorks.sql" -schemaonly
Command to run which will create data:
C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz script -d AdventureWorks "C:\AdventureWorks.sql" -dataonly
VikramRank #9,295 · 208 reputationPosted Dec 9, 2009, 1:42 AM EST
Thanks for your reply. Its working fine. But it gives schema of all objects, actually I want schema of tables only. Is is possible with same option.
Thanks,
Amit Gautam3 reputationPosted Jul 27, 2010, 5:07 AM EDT
code is-
protected void Button1_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = @"C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\sqlpubwiz";
p.StartInfo.Arguments= @"script -d AdventureWorksC:\AdventureWorks.sql";
p.Start();
}
jayakrishnan Morayur156 reputationPosted Mar 10, 2011, 7:31 PM EST
"An error has occured while cnnection to database"
please replay