Enterprise library 用户的企业库5登录失败
我刚刚开始使用EnterpriseLibrary5数据访问应用程序块,但我不断收到登录失败的错误 我已经尝试了在没有应用程序块的情况下使用的连接字符串,并且连接打开良好,但是一旦我在应用程序块上使用相同的连接字符串,它就会失败 我使用DAAB的代码如下:Enterprise library 用户的企业库5登录失败,enterprise-library,daab,Enterprise Library,Daab,我刚刚开始使用EnterpriseLibrary5数据访问应用程序块,但我不断收到登录失败的错误 我已经尝试了在没有应用程序块的情况下使用的连接字符串,并且连接打开良好,但是一旦我在应用程序块上使用相同的连接字符串,它就会失败 我使用DAAB的代码如下: public List GetAgents() { 数据库db=EnterpriseLibraryContainer.Current.GetInstance(“LBDashData”); 字符串sql=“Users\u GetUsers”;
public List GetAgents()
{
数据库db=EnterpriseLibraryContainer.Current.GetInstance(“LBDashData”);
字符串sql=“Users\u GetUsers”;
DbCommand cmd=db.GetStoredProcCommand(sql);
List oAgents=新列表();
使用(IDataReader dataReader=db.ExecuteReader(cmd))
{
while(dataReader.Read())
{
AgentInfo oAgent=new AgentInfo();
oAgent.ItemID=Convert.ToInt32(dataReader[“ItemID”].ToString());
oAgent.ParentID=Convert.ToInt32(dataReader[“ParentID”].ToString());
oAgent.TeamID=Convert.ToInt32(dataReader[“TeamID”].ToString());
oAgent.Team=dataReader[“Team”].ToString();
oAgent.AgentName=dataReader[“AgentName”].ToString();
oAgent.NodeType=dataReader[“NodeType”].ToString();
oAgents.Add(oAgent);
}
}
返回oAgents;
}
配置中的我的连接字符串设置如下:
找到问题的解决方案:) 我在存储过程中有使用链接服务器的表,一旦我为链接服务器设置了正确的模拟,生活又好了
public List<AgentInfo> GetAgents()
{
Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>("LBDashData");
string sql = "Users_GetUsers";
DbCommand cmd = db.GetStoredProcCommand(sql);
List<AgentInfo> oAgents = new List<AgentInfo>();
using (IDataReader dataReader = db.ExecuteReader(cmd))
{
while (dataReader.Read())
{
AgentInfo oAgent = new AgentInfo();
oAgent.ItemID = Convert.ToInt32( dataReader["ItemID"].ToString());
oAgent.ParentID = Convert.ToInt32(dataReader["ParentID"].ToString());
oAgent.TeamID = Convert.ToInt32(dataReader["TeamID"].ToString());
oAgent.Team = dataReader["Team"].ToString();
oAgent.AgentName = dataReader["AgentName"].ToString();
oAgent.NodeType = dataReader["NodeType"].ToString();
oAgents.Add(oAgent);
}
}
return oAgents;
}
<connectionStrings><add name="LBDashData" connectionString="Data Source=(local);Initial Catalog=LBDash;Persist Security Info=True;User id=<userid>;password=<password>" <providerName="System.Data.SqlClient" /></connectionStrings>
public bool testConn ()
{
SqlConnection oconn = new SqlConnection("Data Source=(local);Initial Catalog=LBDash;Persist Security Info=True;User id=<userid>;password=<password>");
try
{
oconn.Open();
return true;
}
catch
{
return false;
}
finally
{
oconn.Close();
}
}