I am attempting to write a C# program that will create stored procedures that are aalready defined/programmed in SQL script files.

So far, I have been able to get connected to my database and created a stored procedure by setting the SQLDMO.StoredProcedure.Text property. But, the real goal is to load and execute scripts that have the stored procedure definition already in them.

Here's what my code looks like AFTER I have gotten the connection to my database:

SQLDMO.StoredProcedure sp = new SQLDMO.StoredProcedure();
sp.Name = "DAVE";
sp.Owner = "[dbo]";
sp.Type = SQLDMO.SQLDMO_PROCEDURE_TYPE.SQLDMOProc_Standard;
sp.Text = "Create procedure [dbo].DAVE as select * from systemrelease";
dbTarget.StoredProcedures.Add(sp);

But, what I had hoped to do was:

SQLDMO.StoredProcedure sp = new SQLDMO.StoredProcedure();
sp.Name = "DAVE";
sp.Owner = "[dbo]";
sp.Type = SQLDMO.SQLDMO_PROCEDURE_TYPE.SQLDMOProc_Standard;
sp.Script(0, "C:\DAVE.sql", 0);
dbTarget.StoredProcedures.Add(sp);

This raises and exception: This property or method is not available until the object has been added to a collection.

Evidently, I am attempting to subvert the big picture.

Can anyone help clear the fuzziness up on my picture? Or am I attempting to do something the SQLDMQ doesn't do?

Thanks in advance for any help...

/dave