|
Comments
|
|
really nice - but where can I copy the code example?
|
|
|
This is really very help ful, but when I execute the generated script, I am getting error of some depending tables which are later in the list but their references were on the top.
Need to do some modifications with the DependencyTree, DependencyWalker and DependencyCollection object of .net framework.
|
|
|
Very Use full
|
|
|
Very quick and simple for programmatically getting the objects from the database.
|
|
|
great code/lesson
|
|
|
Gud work.. it works grt..
I tried using the code
Once it gets the scripts I want to backup and restore the database too
I tried it as below.. its getting the scripts but not backing the database
its not even prompting me any errors
here i am executing this program from a remote server that should not be a problem right..
Thanks..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections.Specialized;
using Microsoft.SqlServer.Management.Smo;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
StreamWriter writer = new StreamWriter(@"c:\script_output.txt", false);
Server s = new Server("servername");
Database db = s.Databases["AdventureWorks"];
// Set up the scripting options to be used below.
ScriptingOptions so = new ScriptingOptions();
so.Permissions = true;
so.Indexes = true;
so.IncludeIfNotExists = true;
// First script the database itself
StringCollection coll = db.Script(so);
foreach (string str in coll)
{
writer.WriteLine(str);
}
// Now script each of the tables
foreach (Table t in db.Tables)
{
StringCollection col2 = t.Script(so);
foreach (string str2 in col2)
writer.WriteLine(str2);
}
// Now script each of the Users
foreach (User u in db.Users)
{
StringCollection col3 = u.Script(so);
foreach (string str3 in col3)
writer.WriteLine(str3);
}
// Now Script each of the Userdefinedfunc
foreach (UserDefinedFunction d in db.UserDefinedFunctions)
{
StringCollection col4 = d.Script(so);
foreach (string str4 in col4)
writer.WriteLine(str4);
}
Backup bkp = new Backup();
bkp.Devices.AddDevice(@"C:\AdventureWorks.bak", DeviceType.File);
//bkp.Database(db);
bkp.Database = "AdventureWorks";
bkp.Action = BackupActionType.Database;
bkp.Initialize = true;
bkp.PercentCompleteNotification = 10;
bkp.PercentComplete += new PercentCompleteEventHandler(bkp_PercentComplete);
bkp.SqlBackup(s);
writer.Flush();
writer.Close();
}
static void bkp_PercentComplete(object sender, PercentCompleteEventArgs e)
{
Console.WriteLine(e.Percent.ToString() + "% backed up");
}
}
}
|
|
|
Just Excellent. Thank you very much.
|
|
|
cracking demo
|
|
|
How about a copy of the source code shown?
|
|
|
This was great! can we have another one to compare objects in a different server?
|
|
|
great job..
|
|
|
Thanks
|
|
|
nice.
|
|
|
beauty
|
|
|
What is a good source to start learning how to program in SQL Server SMO?
|
|
|
I try to run the code with VS 2010 and I got error on
// Add SMO namespaces for less typing later
using Microsoft.SqlServer.Management.Smo;
Error 5 The type or namespace name 'Management' does not exist in the namespace 'Microsoft.SqlServer'
|
|
|
Really good, to the point, and is the first time I've bothered to look at SMO. I feel like going after it big time now.
Thanks for taking the time to push this information out!
|
|
|
Very cool.
|
|
|
Great video. I decided to try my hand at SMO and found that I had to manually browse for and add references to the corresponding assemblies. Very clean and easy.
|
|
|
Execellent...Keep up the great work..it's a habbit of mine to wtahc these vidoes whenever I can ...Thx
|
|
|
BAD AUDIO...PLEASE REPOST.
|
|
|
Great demo...
|
|
|
it is very clear and explanatory
|
|
|
Thanks.. very good
|
|
|
Very handy to know.
|
|
Russell Todd on
5/14/2011
vb.net please
|
|
|
Good to know the SMO..i am beginer
|
|
|
Good to know the SMO..i am beginer
|
|
|
what are the other options of scrpting that allowed to to include indexes and such
|
|
Maurice Ivory on
10/18/2011
I will have to say that the task was made much easier by SMO. I can see the usefullness in this.
|