Rotem Orbach Rotem Orbach -4 years ago 93
C# Question

What is the best practice to manage stored procedures in C# code?

I'm quite new here, so please forgive me if I made any deviation from the rules of this website.

I'm trying to find the best way possible to manage the names of a stored procedure in code.

Currently when I'm calling a stored procedure I'm using this code:

public static DataSet GetKeyTables()
DataSet ds = new DataSet();
ds = SqlDBHelper.ExecuteMultiSelectCommand("Sp_Get_Key_Tables",
return ds;

But I don't think that stating the name of the stored procedure in code is a wise idea, since it will be difficult to track.

I thought about Enum or
solutions, but I'm not sure these are the best ways.

Any idea will be highly appreciated.

Answer Source

You can have a class with constant properties having names of the SPs.And have this class in a seperate class library (dll). Also it is not good to have sp_ as start of procedure see the link

public class StoredProcedures
    public const string GetKeyTables = "Sp_Get_Key_Tables";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download