Databases Reference
In-Depth Information
Scripter scripter = new Scripter();
string fileName = “..\\..\\scriptDB.xml”;
//Create an XML text writer, which will be used to script the command.
System.Xml.XmlTextWriter writer =
new System.Xml.XmlTextWriter(fileName,Encoding.UTF8);
//Create an array of major objects. In this example, the array contains
//just one element.
MajorObject[] objects = new MajorObject [] { db };
//Script the Alter command.
scripter.ScriptAlter(objects, writer, false);
//Close the XML writer.
writer.Close();
}
To simplify the scripting of objects even further, especially in cases where you have a
single object to script or need to script processing operations and batches of the
commands, the
Scripter
object has a number of static methods you can use:
.
WriteStartBatch
—Generates a
<Batch>
element for the DDL
Batch
command. For
more information about the
Batch
command, see Chapter 26.
.
WriteEndBatch
—Generates a closing
</Batch>
element for the
Batch
command.
.
WriteStartParallel
—Generates a
<Parallel>
element, which you can use inside
the
Batch
command to execute inner commands in parallel.
.
WriteEndParallel
—Generates a closing
</Parallel>
element.
.
WriteCreate
—Generates a DDL
Create
command.
.
WriteAlter
—Generates a DDL
Alter
command.
.
WriteDelete
—Generates a DDL
Delete
command.
.
WriteProcess
—Generates a DDL
Process
command.
For example, you can use the
WriteStartBatch
command to generate an opening XML
element
Batch
, and then use
WriteProcess
in a loop to generate
Process
commands to
process all databases or all the partitions in a measure group. Then, you close the
Batch
command with
WriteEndBatch
method, as shown in Listing 34.13.
LISTING 34.13
Scripting a
Batch
Operation Containing Multiple Processing Operations
//Create a Server object.
using (Server srv = new Server())
{
//Connect to the server.
srv.Connect(“localhost”);
Scripter scripter = new Scripter();
string fileName = “..\\..\\scriptDBBatch.xml”;
Search WWH ::
Custom Search