Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i deployed my own web site, but retrieving data from DB is very slow ..
This is sample of my code


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection conGet = new SqlConnection(DataBase.ConnectionString);
            try
            {
                SqlCommand cmdGet = new SqlCommand("SELECT LocalPageText FROM LocalPages WHERE (LocalPageName = 'ContactUS')", conGet);
                SqlDataAdapter daGet = new SqlDataAdapter(cmdGet);
                DataSet dsGet = new DataSet();
                daGet.Fill(dsGet);
                ContactLiteral.Text = dsGet.Tables[0].Rows[0]["LocalPageText"].ToString();
            }
            catch (SqlException)
            {
            }
            finally
            {
                conGet.Close();
            }
        }
    }



But this code run fast ...

try
{
    SqlCommand cmd = new SqlCommand();
    cmd = new SqlCommand("selectCourses", con);
    cmd.CommandType = CommandType.StoredProcedure;
    con.Open();
    SqlDataReader sqlReader = cmd.ExecuteReader();
    DataTable dt = new DataTable();
    dt.Load(sqlReader);

    GridView1.DataBind();
    con.Close();
    cmd.Dispose();

}
catch
{
}
finally
{

}



What's your Opinion ??
Posted

Try doing all sql from Stored Procedures (I find it more secure)

I would also try and seperate the SQL calling area to a DAL Namespace and Class. and BLL to handle the returning of the data.You could then create this as a static function to return the page content based on the name you send it as a parameter.
 
Share this answer
 
hi,

use second option because Stored procedures are pre-compiled so its execution time will be fast .
so it is a good habit to use stored procedures .. and it is simple...
 
Share this answer
 
Use Stored procedures and it is very easy and simple too. It is pre-compiled too. so its execution time will be fast, when compared to the adding a Namespace and class.
so it is a good habit to use stored procedures, i used to do by SP only.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900