简体   繁体   中英

Smo user created stored procedure

When I try to get the list of stored procedures from db by using smo, it lists a lot of stored procedures even if the database is empty.

I want to be able to get a list of stored procedures that are not system procedures. IsSystemObject is not working.

ServerConnection serverConnection = new ServerConnection(sqlConnection);
myserver = new Server(serverConnection);
Database mydb = new Database();
mydb = myserver.Databases[cmbDbname.Text];
string classGenerated = "";
foreach (StoredProcedure mystr in mydb.StoredProcedures)
{
    if (!mystr.IsSystemObject)
    {
        classGenerated += mystr.Name + Environment.NewLine;
    }
}
spClassText.Text = classGenerated;

Here, when I remove the !mystr.IsSystemObject clause, it returns a lot of stored procedures, else does not return my stored procedure created as a test.

try this code

if (mystr.Owner != "sys") 
{
        classGenerated += mystr.Name + Environment.NewLine;
} 

Use the Schema-attribute like this:

if (mystr.Schema != "sys")
{
    classGenerated += mystr.Name + Environment.NewLine;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM