开发者

Enterprise library 5 login failed for user

开发者 https://www.devze.com 2023-02-16 12:13 出处:网络
I\'ve just started to use the enterprise library 5 data access application block, but I keep on getting login failed errors.

I've just started to use the enterprise library 5 data access application block, but I keep on getting login failed errors.

I've tried the connection string that I'm using without the application block and the connection opens fine, but as soon as I use the same connection string with the application block it fails.

My code that utilises the DAAB is as follows:


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.ToInt开发者_开发问答32(dataReader["TeamID"].ToString());
                oAgent.Team = dataReader["Team"].ToString();
                oAgent.AgentName = dataReader["AgentName"].ToString();
                oAgent.NodeType = dataReader["NodeType"].ToString();

                oAgents.Add(oAgent);
            }
        }

        return oAgents;
    }

My connection string in the config has been set up as follows:


<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>

If I try the same connection string with the following code it works

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

Does anyone have any ideas what I can try next?


Found solution to problem :)

<hangs head in shame>

I had tables in stored procedure that were using a linked server, once I set up the correct impersonation for the linked server, life was good again.

0

精彩评论

暂无评论...
验证码 换一张
取 消