2011-03-10 58 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

找到解決問題:)

< 掛頭恥辱>

我曾在存儲過程中的表使用鏈接的服務器,一旦我設置爲鏈接服務器的正確模擬,生活又恢復了良好。