Sunday, June 29, 2014

Performance problem to load data from sql server!

Hi


in my app, we have a report which get data from sql server proc. my problem is in database server, this proc take 2-3 seconds to load data from ssms but in my app (which exists on database server), it takes 20-30 seconds (or higher) to load and make cause TimeOut exception.


here is my code to run proc and get data from sql server :



public static DataTable GetDataByProcedure(string procName, Dictionary<string, object> parameters, string connectionString)
{
DataTable dtResult = new DataTable();
try
{
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = procName;
cmd.CommandType = CommandType.StoredProcedure;

if (parameters != null)
{
foreach (string parameter in parameters.Keys)
{
cmd.Parameters.AddWithValue(parameter, parameters[parameter]);
}
}

if (con.State != ConnectionState.Open)
con.Open();

dtResult.Load(cmd.ExecuteReader());

if (con.State != ConnectionState.Closed)
con.Close();
}
}
catch { return dtResult; }
return dtResult;
}



however, the above code is really clear and straightforward, but I think there is a faster way to get data from sql server like ssms!!!


can anybody help me ?


thanks in advance




http://ift.tt/1bGq8Xs


No comments:

Post a Comment