2011-03-10 55 views
0

我刚开始使用企业库5数据访问应用程序块,但我一直在获取登录失败的错误。企业库5登录失败用户

我试过连接字符串,我没有应用程序块和连接打开罚款,但只要我使用相同的连接字符串与应用程序块失败。

我的代码,它利用DAAB如下:


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(); 
     } 
    } 

没有人有任何想法我可以尝试下?

回答

0

找到解决问题:)

< 挂头耻辱>

我曾在存储过程中的表使用链接的服务器,一旦我设置为链接服务器的正确模拟,生活又恢复了良好。