首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >企业库5用户登录失败

企业库5用户登录失败
EN

Stack Overflow用户
提问于 2011-03-10 09:53:41
回答 1查看 513关注 0票数 0

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

我已经尝试了在没有应用程序块的情况下使用的连接字符串,并且连接打开得很好,但是一旦我在应用程序块中使用相同的连接字符串,它就会失败。

我使用DAAB的代码如下:

代码语言:javascript
复制
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;
    }

配置中的连接字符串设置如下:

代码语言:javascript
复制
<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>

如果我用下面的代码尝试相同的连接字符串,它就会工作

代码语言:javascript
复制
        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();
        }
    }

有谁知道我下一步可以尝试什么吗?

EN

回答 1

Stack Overflow用户

发布于 2011-03-10 14:06:25

找到解决问题的办法:)

< shame>中的垂头

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5257944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档