Hello,
I'm creating an asp.net application (one of the many I've done).
But this is the first time I've encountered this specific problem.
When I press a button on a page the first time (so the application is already loaded) this is very very slow.
After the first time I've clicked the button, all other calls on that page go really fast (as it should be).
I've opened sql profiler and charles (http debugger) to see what is happening and the funny part is: The page itself is slow, the queries that are executed take +- 50ms in total to be executed but it takes 18 seconds to initiate the call to the database.
So the .net code takes very very long before it starts his sql code. I really don't get it. I hope someone can help me out.
This is how my application layer is done:
Masterpage --> page --> usercontrol (within repeater) --> button.
The button just executes a service layer who will access the repository layer which will commence the call to the database.
Here is the logging that I got.
this is my application structure:
UserService --> UserRepository : RepositoryBase --> dataAccess. The code:
public User GetByEmailAndPassword(string email, string password)
{
_log.Info("UserRepository.GetByEmailAndPassword - Start");
this.Test();
User result = null;
List<DbParam> parameters = new List<DbParam>();
parameters.Add(new DbParam("@Email", email, DbType.String));
parameters.Add(new DbParam("@Password", password, DbType.String));
_log.Info("UserRepository.GetByEmailAndPassword - Entering reader");
var reader = ExecuteReader("User_GetByEmailAndPassword", parameters);
if (reader.Read())
{
result = _entityFactory.ConvertToModel(reader);
}
reader.Close();
_log.Info("UserRepository.GetByEmailAndPassword - End");
return result;
}
The repository base:
public abstract class RepositoryBase<T>
where T : IEntity
{
private static ILog _log = LogManager.GetLogger(typeof(RepositoryBase<T>));
protected IEntityFactory<T> _entityFactory;
protected RepositoryBase()
{
_log.Info("Constructor");
_entityFactory = EntityFactoryBuilder.BuildFactory<T>();
}
protected IDataReader ExecuteReader(string storedProc, List<DbParam> parameters)
{
_log.Info("ExecuteReader - Start");
_log.Info("Open connection");
var db = DatabaseFactory.CreateDatabase();
_log.Info("Open command");
var dbCommand = db.GetStoredProcCommand(storedProc);
foreach (DbParam param in parameters)
{
db.AddInParameter(dbCommand, param.Name, param.Type, param.Value);
}
_log.Info("Execute command");
var reader = db.ExecuteReader(dbCommand);
_log.Info("ExecuteReader - End");
return reader;
}
}
The logging shows that it takes 14 seconds just to enter this function.
var reader = ExecuteReader("User_GetByEmailAndPassword", parameters);
THIS ISN'T EXECUTING IT BUT JUST ENTERING THE FUNCTION.
I'm startled I really have no idea why calling upon a function in a base class is taking this long.
I could add some logging data but it just shows what I'm telling here.
Could it be that this is a property due to virtual servers?
Because testing the same application on a non virtual server doesn't have this problem at all.
Cheers, M.