最近做项目,用到了Ibaits这种ORM映射,就写了一个获取动态sql的辅助代码:
/// <summary>
/// 得到运行时的IbatisNet动态生成的SQL语句
/// </summary>
/// <param name="sqlMapper">获取关联SqlMapper对象</param>
/// <param name="statementName">xml中节点名称</param>
/// <param name="paramObject">xml中节点的参数</param>
/// <returns>生成的Sql语句或者错误</returns>
public static string GetRuntimeSql(ISqlMapper sqlMapper, string statementName, object paramObject)
{
string result = string.Empty;
try
{
IMappedStatement statement = sqlMapper.GetMappedStatement(statementName);
if (!sqlMapper.IsSessionStarted)
{
sqlMapper.OpenConnection();
}
RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, paramObject, sqlMapper.LocalSession);
result = scope.PreparedStatement.PreparedSql;
return result;
}
catch (Exception ex)
{
return result = "获取SQL语句出现异常:" + ex.Message;
}
}可是就是这句话,服务端发布了以后,如果频繁操作老是把服务弄挂,必须重启后才可以,报的错是连不上数据库,怎么回事呢?这句话怎么能导致连不上数据库。这个问题搞了好几天才发现,求助大牛解说!!!
/// <summary>
/// 得到运行时的IbatisNet动态生成的SQL语句
/// </summary>
/// <param name="sqlMapper">获取关联SqlMapper对象</param>
/// <param name="statementName">xml中节点名称</param>
/// <param name="paramObject">xml中节点的参数</param>
/// <returns>生成的Sql语句或者错误</returns>
public static string GetRuntimeSql(ISqlMapper sqlMapper, string statementName, object paramObject)
{
string result = string.Empty;
try
{
IMappedStatement statement = sqlMapper.GetMappedStatement(statementName);
if (!sqlMapper.IsSessionStarted)
{
sqlMapper.OpenConnection();
}
RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, paramObject, sqlMapper.LocalSession);
result = scope.PreparedStatement.PreparedSql;
return result;
}
catch (Exception ex)
{
return result = "获取SQL语句出现异常:" + ex.Message;
}
}可是就是这句话,服务端发布了以后,如果频繁操作老是把服务弄挂,必须重启后才可以,报的错是连不上数据库,怎么回事呢?这句话怎么能导致连不上数据库。这个问题搞了好几天才发现,求助大牛解说!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货