Every developer is recommended to use stored procedures instead of embedded SQL queries while implementing ADO.Net data access model in ASP.Net web applications. There are number of reasons based on data access model performance and efficiency that suggests the use of stored procedures instead of using hardcode sql queries in ASP.Net code. Further in this article we will discuss about some of the reasons to avoid the use of dynamic SQL queries in ASP.Net code.
Stored procedures are precompiled objects that contain one or more sql queries. The structure of a stored contains the name of stored procedure, declaration of input or output variables and last sql statements. Stored procedures are the permanently compiled objects stored in the database that encapsulates the complex sql queries from the application.
In ASP.Net code you must use CommandType.StoredProcedure to direct the SqlCommand object that the passed argument is a name of stored procedure. You can use SqlDataAdapter to fill the DataSet by passing the name of stored procedure directly without creating the SqlCommand object because overloaded SqlDataAdapter creates the SqlCommand object internally.
Main reasons of using stored procedures in ASP.Net web applications over the dynamic or embedded sql queries:
While creating procedures required for data access do not use “sp_” as a prefix for naming the stored procedure. Stored procedures starting with “sp_” are assigned to the system stored procedures. SQL server looks for the stored procedures having name prefix as “sp_”:
Currently rated 5.0 by 2 people
Tags: asp.net, stored procedures, sql queries, stored procedures vs dynamic sql queries, what are stored procedures
10/14/2008 1:07:43 PM