Click here to Skip to main content
15,912,082 members
Home / Discussions / C#
   

C#

 
GeneralRe: Alternative view Pin
Yaakov Davis5-Jan-05 12:17
Yaakov Davis5-Jan-05 12:17 
GeneralRe: Alternative view Pin
Robert Rohde5-Jan-05 18:57
Robert Rohde5-Jan-05 18:57 
GeneralHosting Browser Control in Win Form Pin
eliea5-Jan-05 10:22
eliea5-Jan-05 10:22 
GeneralRe: Gradient ToolBar Pin
bigals5-Jan-05 10:06
bigals5-Jan-05 10:06 
QuestionSQLDMO help??? Pin
JMichael24685-Jan-05 10:04
JMichael24685-Jan-05 10:04 
AnswerRe: SQLDMO help??? Pin
perlmunger5-Jan-05 14:16
perlmunger5-Jan-05 14:16 
GeneralRe: SQLDMO help??? Pin
JMichael24686-Jan-05 3:28
JMichael24686-Jan-05 3:28 
GeneralRe: SQLDMO help??? Pin
perlmunger6-Jan-05 4:36
perlmunger6-Jan-05 4:36 
I recently wrote an article[^] for codeproject where the application involved uses a utility class for generating scripts. Here is the pertinent method from that class:
public static string GetScript(string hostName, string dbName, string username, string password, string prefix )
{
// Instantiate the Sql Server Object
SQLDMO.SQLServer srv = new SQLDMO.SQLServer();

// If there is no username provided, we assume that we're going to use
// a trusted connection
if( username.Length <= 0 )
{
	srv.LoginSecure = true;
	srv.Connect( hostName, "", "" );
}
// Otherwise we log in with the specified credentials
else
	srv.Connect(hostName, username, password );

// We have to set some scripting parameters before we start
SQLDMO.SQLDMO_SCRIPT_TYPE param = SQLDMO_SCRIPT_TYPE.SQLDMOScript_Default |
	// Script out indexes
	SQLDMO.SQLDMO_SCRIPT_TYPE.SQLDMOScript_Indexes |
	// Script out drop statements
    SQLDMO_SCRIPT_TYPE.SQLDMOScript_Drops |
	// Prefix the object name with the database owner
	SQLDMO_SCRIPT_TYPE.SQLDMOScript_OwnerQualify;

string script = "";
foreach(SQLDMO.Database db in srv.Databases)
{
	// Have to iterate through the list of databases to find the one that was specified
	if(db.Name!=null && db.Name.ToLower().Equals(dbName.ToLower()) )
	{
		// First search through all of the tables and locate the ones
		// with the prefix provided
		foreach( SQLDMO.Table table in db.Tables )
		{
			if( table.Name.ToLower().StartsWith( prefix.ToLower() ) )
			{
				// Append the script for the current table
				script += table.Script( param, null, null, SQLDMO.SQLDMO_SCRIPT2_TYPE.SQLDMOScript2_Default );
			}
		}
		// Next search through all of the stored procedures and locate the ones
		// with the prefix provided
		foreach( SQLDMO.StoredProcedure proc in db.StoredProcedures )
		{
			if( proc.Name.ToLower().StartsWith( prefix.ToLower() ) )
			{
				// Append the script for the current stored procedure
				script += proc.Script( param, null, SQLDMO.SQLDMO_SCRIPT2_TYPE.SQLDMOScript2_Default );
			}
		}
		break;
	}
}
return script;

}

Notice that I don't use the Databases.Item method. Instead I iterate through until I find the one with the name equal to the name of the db I want. I'm not sure if this matters, but hopefully it can be of some help.

Also notice that I am not using the Database2 object, however, after a few tests with using the same code and the Database2 object instead on my local machine, I am convinced it does work the way you expect--it will just provide you with the list of functions you need instead sprocs and tables.

Best Regards.

-Matt

p.s. All of this *may* be a moot point if you don't have the latest service pack for SQL Server 2K, though this is just a hunch and may not be related and/or causing the problem. Wink | ;-)

------------------------------------------

The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
GeneralRe: SQLDMO help??? Pin
JMichael24686-Jan-05 4:57
JMichael24686-Jan-05 4:57 
GeneralRe: SQLDMO help??? Pin
perlmunger6-Jan-05 5:24
perlmunger6-Jan-05 5:24 
Generalqueuing outgoing tcp packets Pin
sciamachy5-Jan-05 9:37
sciamachy5-Jan-05 9:37 
Questionmake a mirror print?? Pin
bigmega5-Jan-05 9:21
bigmega5-Jan-05 9:21 
AnswerRe: make a mirror print?? Pin
Christian Graus5-Jan-05 12:03
protectorChristian Graus5-Jan-05 12:03 
GeneralRe: make a mirror print?? Pin
bigmega6-Jan-05 6:54
bigmega6-Jan-05 6:54 
GeneralRe: make a mirror print?? Pin
Christian Graus6-Jan-05 9:02
protectorChristian Graus6-Jan-05 9:02 
GeneralUpdate Large DataTable Pin
Wayne Phipps5-Jan-05 9:17
Wayne Phipps5-Jan-05 9:17 
GeneralRe: Update Large DataTable Pin
Bill Dean5-Jan-05 9:46
Bill Dean5-Jan-05 9:46 
GeneralRe: Update Large DataTable Pin
Wayne Phipps5-Jan-05 10:01
Wayne Phipps5-Jan-05 10:01 
GeneralRe: Update Large DataTable Pin
Robert Rohde5-Jan-05 19:07
Robert Rohde5-Jan-05 19:07 
GeneralMultithreading... Pin
Peter Molnar5-Jan-05 8:13
Peter Molnar5-Jan-05 8:13 
GeneralRe: Multithreading... Pin
leppie5-Jan-05 11:51
leppie5-Jan-05 11:51 
GeneralRe: Multithreading... Pin
Charlie Williams5-Jan-05 11:52
Charlie Williams5-Jan-05 11:52 
Questionhow to insert a record to Access database ? Pin
DuyNguyen5-Jan-05 7:57
DuyNguyen5-Jan-05 7:57 
AnswerRe: how to insert a record to Access database ? Pin
Charlie Williams5-Jan-05 11:46
Charlie Williams5-Jan-05 11:46 
GeneralFun with SetSocketOption Pin
tantiboh5-Jan-05 7:53
tantiboh5-Jan-05 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.