Help with Microsoft.SqlServer.Management.Smo StoredProcedure C #

1

I am programming an application in C # to extract the stored procedures from a database and generate the corresponding scripts. The problem I get is that when I get the StoreProcedure objects, it brings me the SystemStoreProcedures as well, I have been searching for information but I have not found any code to filter it, I thought of doing the following:

1) I get the procedures of a database:

StoredProcedureCollection spcoll = srv.Databases["demo"].StoredProcedures;

2) Then I go through the list with a foreach to filter the store procedures that are system and leave them in a new list where I will finally get the stored procedures that I want to get out.

List<StoredProcedure> lista = new List<StoredProcedure>();

foreach (StoredProcedure item in spcoll)
{
   if (item.IsSystemObject == false)
      {
         lista.Add(item);
       }
}

This works correctly, I add the StoreProcedure that corresponds to the database and that are not system to the list, the problem in doing this takes too much between 10-20 seconds, my query is if there is a more efficient way to do this.

Greetings.

    
asked by Nicolas Andres Rosales Arce 22.06.2017 в 23:40
source

1 answer

1

What you could do is create a secondary thread so that the application does not crash. This you could do create a method with that code that you wrote and call it from a secondary thread (Theard).

Here I leave some links so you can see how they are made: link

link

There is information about the Thread and the BackgroundWorker.

Greetings

    
answered by 23.06.2017 / 15:36
source