0

我刚刚开始使用企业库 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();
        }
    }

有谁知道我接下来可以尝试什么?

4

1 回答 1

0

找到问题的解决方案:)

<羞愧地低下头>

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

于 2011-03-10T14:06:25.063 回答