ScriptData doesn't script data
-
Monday, October 06, 2008 6:53 PMThe only thing I can get out of ScriptingOptions.ScriptData is:
"This method does not support scripting data."
I've tried:
Dim ObjectToScript() As Urn = New Urn(0) {oUrn}
For Each str As String In _oScripter.Script(ObjectToScript)
_script.Add(str)
Next
and
Dim opts As New ScriptingOptions
opts.Add(ScriptOption.ScriptData)
oTable.Script(opts)
All I get is the above message... as a fatal error...
How is it supposed to be used?
Thanks for any additional information.
Bill Wunder
PS: When the elections are over I may suggest that SNL take a look at the SMO documentation for some new material.
All Replies
-
Tuesday, October 07, 2008 7:36 AMAnswerer
Hi,
If you are looking to script a table with data you can try using EnumScript methods in Scripter.
Server server = new Server(serverConnection);ServerConnection serverConnection = new ServerConnection(".");
Database database = server.Databases["AdventureWorks"];
Table tb = database.Tables[ "Address","Person"];
Scripter scripter = new Scripter(server);
scripter.Options.ScriptData = true;
foreach (string s in scripter.EnumScript(new Urn[]{tb.Urn}))
Console.WriteLine(s);
I will ask documentation team to make sure this behavior is documented.
(It would be fun watching SNL take a look at SMO documentation)
Thanks,
Alok Parmesh -
Tuesday, October 07, 2008 12:27 PMThank You Alok, that made it easy...
Yea yea, I can see it now, SNL would have a cool-aid orange haired old guy with a page sized rubber stamp and a wild look in his eye making documentation pages - each just like the last then filling in the blank space for the member name and giggling as he crosses off another line on a huge list and shouts "Done!" -
Thursday, November 27, 2008 6:01 AM
Alok Parmesh - MSFT wrote: Hi,
If you are looking to script a table with data you can try using EnumScript methods in Scripter.
Server server = new Server(serverConnection);ServerConnection serverConnection = new ServerConnection(".");
Database database = server.Databases["AdventureWorks"];
Table tb = database.Tables[ "Address","Person"];
Scripter scripter = new Scripter(server);
scripter.Options.ScriptData = true;
foreach (string s in scripter.EnumScript(new Urn[]{tb.Urn}))
Console.WriteLine(s);
I will ask documentation team to make sure this behavior is documented.
(It would be fun watching SNL take a look at SMO documentation)
Thanks,
Alok Parmesh
Hi Alok,
I am just converting to C# and .Net from Delphi and tried to use your example code but can't understand why I keep getting errors in the EnumScript(new Urn[]{tb.Urn})) method.
Error 1 The best overloaded method match for 'Microsoft.SqlServer.Management.Smo.Scripter.EnumScript(Microsoft.SqlServer.Management.Smo.SqlSmoObject[])' has some invalid arguments D:\Projects\VStudio\ConsoleApplication1\ConsoleApplication1\Program2.cs 25 34 ConsoleApplication1
Error 2 Argument '1': cannot convert from 'Urn[]' to 'Microsoft.SqlServer.Management.Smo.SqlSmoObject[]' D:\Projects\VStudio\ConsoleApplication1\ConsoleApplication1\Program2.cs 25 54 ConsoleApplication1
Error 3 The type or namespace name 'Urn' could not be found (are you missing a using directive or an assembly reference?) D:\Projects\VStudio\ConsoleApplication1\ConsoleApplication1\Program2.cs 25 58 ConsoleApplication1
I have included the following namespaces
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Diagnostics;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
many thanks, Paul -
Thursday, November 27, 2008 7:07 AMOh one other question, is the smoenum.dll assembly still installed as part of SQL 2008 because I can't find it on my system?
-
Thursday, November 27, 2008 10:03 AMAnswerer
Hi Paul,
Welcome to MSDN forum.
smoenum.dll is no longer part of the SMO so it is not installed.
I think you need to add Microsoft.SqlServer.Management.Sdk.Sfc namespace in using and Microsoft.SqlServer.Management.Sdk.Sfc.dll in reference
Regards,
Alok Parmesh
-
Thursday, November 27, 2008 10:57 AMThanks for the welcome Alok, I'm finding the transition to .NET quite painful so will probably be a very frequent poster for quite awhile :-)
Many thanks for the input and referencing the Microsoft.SqlServer.Management.Sdk.Sfc as you suggested fixed the prob.
Thanks also for the info on smoenum.dll, I was going crazy over that one. I searched the whole web trying to find if it is still part of Server 2008 but found no reference to it being omitted anywhere. Even the MSDN Server 2008 SQL books online still refer to it. Very frustrating !!!
Cheers and thanks again for responding so quickly.
-
Monday, August 31, 2009 6:48 AMI have to generate only the insert statement of all the tables of my database, and I am successfully able to generate the insert scripts , But I would like to know how can I remove the create table scripts from the generated script.
Please advice
Thanks
Manish -
Thursday, September 03, 2009 8:33 AMAh I find out the way to skip the 'Create table statement' just by the following
scripter.Options.ScriptSchema = false;
Well can anyone having any idea, how to have the "Use Database" statement on the top of the script.
Please advice
Thanks
Manish -
Friday, September 04, 2009 7:07 PMAnswererHi,
IncludeDatabaseContext is the option responsible for getting Use Database statements in the script.
Regards,
Alok Parmesh
Mark Post as helpful if it provides any help.Otherwise,leave it as it is. -
Monday, September 07, 2009 1:14 PMHi Alok,
Thank you for your help,
but unfortunately the IncludeDatabaseContext is not working for me.
Thanks
Manish

