Hi,
As suggested by:
[ServiceStack OrmLite Sql Query Logging][1]
var sql = connection.GetLastSql(); will give me the last executed sql.
However i get sth like
UPDATE "Batches" SET "BatchStatusID"=@1 WHERE ("ID" = @0)
The thing is that i need to log also the Parameters.
I do not want to use a Profiler for such a simple task and the purpose is to log the whole sql query in case of an exception.
I’ve hacked it using a
public SpecializedProfiledDbCommand(DbCommand cmd, DbConnection conn, IDbProfiler profiler)
: base(cmd, conn, profiler)
{
ASTATICCLASS.DbParameters.Clear();
ASTATICCLASS.DbParameters.Add(this.Parameters);
}
This way i hold the last parameters and accompanied with the lastSql i can have a proper log.
However this is far from elegant and no threadSafe/AsyncSafe!
I also tried to use a
public class MyProfiler : IDbProfiler
{
public void ExecuteStart(DbCommand profiledDbCommand, ExecuteType executeType)
{
}
public void ExecuteFinish(DbCommand profiledDbCommand, ExecuteType executeType, DbDataReader reader)
{
}
public void ReaderFinish(DbDataReader reader)
{
}
public void OnError(DbCommand profiledDbCommand, ExecuteType executeType, Exception exception)
{
var asd = profiledDbCommand;
}
public bool IsActive { get; }
}
SpecializedProfiledDbConnection
public class SpecializedProfiledDbConnection : ProfiledConnection
{
public SpecializedProfiledDbConnection(DbConnection connection, IDbProfiler profiler, bool autoDisposeConnection = true)
: base(connection, profiler, autoDisposeConnection)
{ }
public SpecializedProfiledDbConnection(IDbConnection connection, IDbProfiler profiler, bool autoDisposeConnection = true)
: base(connection, profiler, autoDisposeConnection)
{ }
protected override DbCommand CreateDbCommand()
{
return new SpecializedProfiledDbCommand(InnerConnection.CreateCommand(), InnerConnection, Profiler);
}
}
DbFactoryInitialization
protected static readonly IDbConnectionFactory DbConnectionFactory =
new OrmLiteConnectionFactory(GlobalConfig.ConnectionString, SqlServerDialect.Provider)
{
ConnectionFilter = connection => new SpecializedProfiledDbConnection(connection, new MyProfiler())
};
However the OnError is never being hit
Thanks