I have a program in C # that when the start and ask to show me the data inserted in the Sql Server takes to open, but after this time is already faster. Is there a way to be faster first time?
My connection is made this way and only use stored procedure:
public class AcessoBaseDadosSqlServer
{
private SqlConnection conexao()
{
return new SqlConnection(Settings.Default.StringConnection);
}
private SqlParameterCollection sqlParameterCollection = new SqlCommand().Parameters;
public void LimparParametros()
{
sqlParameterCollection.Clear();
}
public void AdicionarParametros(string nomeParametro, object valorParametro)
{
sqlParameterCollection.Add(new SqlParameter(nomeParametro, valorParametro));
}
// INSERIR, ALTERAR E APAGAR
public object ExecutarManipulacao(CommandType commandType, string nomeStoredProcedureOuTextoSQL)
{
try
{
// criar um ligação à base de dados
SqlConnection sqlConnection = conexao();
// abrir ligação
sqlConnection.Open();
//criar um comando
SqlCommand sqlCommand = sqlConnection.CreateCommand();
sqlCommand.CommandType = commandType;
sqlCommand.CommandText = nomeStoredProcedureOuTextoSQL;
sqlCommand.CommandTimeout = 7200;
foreach (SqlParameter SqlParameter in sqlParameterCollection)
{
sqlCommand.Parameters.Add(new SqlParameter(SqlParameter.ParameterName, SqlParameter.Value));
}
return sqlCommand.ExecuteScalar();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
// Consulta
public DataTable ExecutarConsulta(CommandType commandType, string nomeStoredProcedureOuTextoSql)
{
try
{
SqlConnection sqlConnection = conexao();
sqlConnection.Open();
SqlCommand sqlCommand = sqlConnection.CreateCommand();
sqlCommand.CommandType = commandType;
sqlCommand.CommandText = nomeStoredProcedureOuTextoSql;
sqlCommand.CommandTimeout = 7200;
foreach (SqlParameter sqlParameter in sqlParameterCollection)
{
sqlCommand.Parameters.Add(new SqlParameter(sqlParameter.ParameterName, sqlParameter.Value));
}
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
DataTable dataTable = new DataTable();
sqlDataAdapter.Fill(dataTable);
return dataTable;
}
catch (Exception)
{
throw;
}
}
}