Do you always prefix SQL stored procedure names with the owner in ADO.NET code?
Updated by Brady Stroud [SSW] 1 year ago. See history
123
Stored procedure names in code should always be prefixed with the owner (usually dbo). This is because if the owner is not specified, SQL Server will look for a procedure with that name for the currently logged on user first, creating a performance hit.
SqlCommand sqlcmd = new SqlCommand(); sqlcmd.CommandText = "proc_InsertCustomer" sqlcmd.CommandType= CommandType.StoredProcedure; sqlcmd.Connection = sqlcon;
❌ Figure: Bad example
SqlCommand sqlcmd = new SqlCommand(); sqlcmd.CommandText = "dbo.proc_InsertCustomer"; sqlcmd.CommandType= CommandType.StoredProcedure; sqlcmd.Connection = sqlcon;
✅ Figure: Good example
We have a program called SSW Code Auditor to check for this rule.