BeginTransaction return 空连接字符串
BeginTransaction return null connectionstring
我将 Dapper ORM 与工作单元一起使用
使用 IDbConnection/IDbTransaction 处理 (Close/Commit/Rollback)
public IDbTransaction BeginTransaction(string connectionName = "", bool useWadminUser = false, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
{
using (DbConnection db = GetDbconnection(connectionName, useWadminUser))
{
db.Open();
_dbTransaction = db.BeginTransaction();
}
return this._dbTransaction;
}
DbConnection GetDbconnection(string connectionName = "", bool useWadminUser = false)
{
UserInfoHelper userInfoHelper = _iSecurityAuthorizService.GetCookieProfileUser();
return new SqlConnection(
string.Format(_config.GetConnectionString(string.IsNullOrEmpty(connectionName) ? SqlHelper.DefaultConnection : connectionName),
SqlHelper.WadminUserName, SqlHelper.WadminPassword));
}
我调用服务 var tran= _dapper.BeginTransaction();
但 tran 为空。
请看这个this pic1
public IDbTransaction BeginTransaction(string connectionName = "", bool useWadminUser = false, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
{
using (DbConnection db = GetDbconnection(connectionName, useWadminUser))
{
db.Open();
_dbTransaction = db.BeginTransaction();
} <-- Here
return this._dbTransaction;
}
在上面的指针处,连接已关闭并已处理,事务处理也已关闭。你不能使用那样的交易。
我将 Dapper ORM 与工作单元一起使用
使用 IDbConnection/IDbTransaction 处理 (Close/Commit/Rollback)
public IDbTransaction BeginTransaction(string connectionName = "", bool useWadminUser = false, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
{
using (DbConnection db = GetDbconnection(connectionName, useWadminUser))
{
db.Open();
_dbTransaction = db.BeginTransaction();
}
return this._dbTransaction;
}
DbConnection GetDbconnection(string connectionName = "", bool useWadminUser = false)
{
UserInfoHelper userInfoHelper = _iSecurityAuthorizService.GetCookieProfileUser();
return new SqlConnection(
string.Format(_config.GetConnectionString(string.IsNullOrEmpty(connectionName) ? SqlHelper.DefaultConnection : connectionName),
SqlHelper.WadminUserName, SqlHelper.WadminPassword));
}
我调用服务 var tran= _dapper.BeginTransaction(); 但 tran 为空。 请看这个this pic1
public IDbTransaction BeginTransaction(string connectionName = "", bool useWadminUser = false, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
{
using (DbConnection db = GetDbconnection(connectionName, useWadminUser))
{
db.Open();
_dbTransaction = db.BeginTransaction();
} <-- Here
return this._dbTransaction;
}
在上面的指针处,连接已关闭并已处理,事务处理也已关闭。你不能使用那样的交易。