Hi P1ST0LPETE,
Have a look at the following:
http://www.unganisha.org/h
http://www.karaszi.com/SQL
Good Luck!
Gary
Main Topics
Browse All TopicsHi,
I'm currently working on a C# program that needs to generate an SQL script. I've discovered that the SQLDMO API will allow me to do everything that the SQL Management Studio can do. The SQL Management Studio can generate scripts by doing the following:
Right click on database object >> Tasks >> Generate Scripts.
In my program I need to create a script file just like the above would produce.
Can anyone help explain how to do this, or point me in the direction of a good tutorial.
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi P1ST0LPETE,
Have a look at the following:
http://www.unganisha.org/h
http://www.karaszi.com/SQL
Good Luck!
Gary
After reading through the links you guys posted, I've come up with the following method (see code snippet). Upon compiling, I'm getting an error on the following line:
SQLDMO.Database db = server.Databases["NetCordD
The error is: "Cannot apply indexing with [ ] to an expression of type 'SQLDMO.Databases'".
In the examples online, that line of code looks like it should work.
What am I doing wrong?
Got it to work by changing the database line to:
SQLDMO.Database db = new SQLDMO.Database();
db = (SQLDMO.Database)server.Da
Final problem: My generated script is not matching the script generated by SQL Server Management Studio. Code snippet below shows the two scripts. As you can see, my script contains a lot of extra stuff that I don't want. What do I need to do to create a matching script?
Ok, sorry for not replying to the answer. The root of the problem, is the project I was working on that this question was associated with, has been put on the back burner while I work on something else. (Ever hear of projects that get started, but then never finished? :-) )
Anyway, if you re-read my original post, you'll see that the root of my question was for direction on how to recreate the script that SQL Management Studio creates. Through the experts posts, I was able to figure out (to a degree) how to go about doing it (i.e. using SQL-DMO or SQL-SMO). However, as you read my last post, you'll see that I was unsuccessful in actually matching the output script and I was asking for further help to which I received no response.
As far as points are concerned, it really doesn't bother me either way. If the points are split between the two experts - fine; if the points are refuned - that's fine too. The experts did point me in the right direction with their links (which I appriciate as I had no previous SQLDMO/SMO experience), but failed to continue to offer help/advice until the problem was solved.
The argument could be made that:
"I need to create a script file just like the above would produce"
from my original post doesn't mean:
"I need a script exactly like SQL Management Studio would produce"
however, that is what I was gunning for and received no help/solution for - as when I made my final post stating this, the experts aparently abandoned the question.
Business Accounts
Answer for Membership
by: reb73Posted on 2009-04-20 at 12:35:20ID: 24187874
Does the link below help?
icle/scrip ting-datab ase-object s- using-sm o-updated
http://www.sqlteam.com/art