数据源的类型无效。它必须是 IListSource、IEnumerable 或 IDataSource

发布于 2024-09-27 15:23:52 字数 752 浏览 0 评论 0原文

我正在将使用 Enterprise Library 版本 2(主要是 DAAB)的 .NET 2.0 站点升级到 .NET 版本 3.5 和 EntLib 版本 5。我已经进行了必要的更改,现在收到错误“数据源是无效类型。它必须是 IListSource、IEnumerable 或 IDataSource”。我在尝试将 DevExpress ASPxGridView 控件的数据源设置为 IDataReader 时收到此错误。

下面是我的代码。我们的应用程序广泛使用 IDataReaders...这些实例都需要修改吗?我在这里看到一篇文章说将 .ToList() 添加到数据源的末尾,但这不是 IDataReader 中的有效方法。请注意,虽然此特定文件是 C#,但我们的应用程序 99% 是用 VB.NET 编码的。

private void GetRecentAddedCasesGridData()
    {
        dbReader = DAL.GetRecentAddedCases(iClientKey);
        if (dbReader != null)
        {
            GridRecentAddedCases.DataSource = dbReader;
            GridRecentAddedCases.DataBind();         
        }
        dbReader.Close();
        dbReader.Dispose();
        dbReader = null;
    }

I'm upgrading a .NET 2.0 site that uses Enterprise Library version 2 (DAAB mainly) to .NET version 3.5 and EntLib version 5. I've made the necessary changes and now I'm getting an error "The data source is of an invalid type. It must be an IListSource, IEnumerable or IDataSource". I'm getting this error trying to set the datasource of a DevExpress ASPxGridView control to an IDataReader.

Below is my code. Our app uses IDataReaders extensively....will these instances all need to be modified? I saw one article here that said to add .ToList() to the end of the data source but that is not a valid method in the IDataReader. Please note that while this particular file is C#, 99% of our app is coded in VB.NET.

private void GetRecentAddedCasesGridData()
    {
        dbReader = DAL.GetRecentAddedCases(iClientKey);
        if (dbReader != null)
        {
            GridRecentAddedCases.DataSource = dbReader;
            GridRecentAddedCases.DataBind();         
        }
        dbReader.Close();
        dbReader.Dispose();
        dbReader = null;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

写给空气的情书 2024-10-04 15:23:52

尝试这个扩展方法

public static IEnumerable<object[]> AsEnumerable(this IDataReader reader)
{
    while (reader.Read())
    {
        var ret = new object[reader.FieldCount];
        reader.GetValues(ret);
        yield return ret;
    }
}

然后你可以写
GridRecentAddedCases.DataSource = dbReader.AsEnumerable()

Try this extension method

public static IEnumerable<object[]> AsEnumerable(this IDataReader reader)
{
    while (reader.Read())
    {
        var ret = new object[reader.FieldCount];
        reader.GetValues(ret);
        yield return ret;
    }
}

Then you can write
GridRecentAddedCases.DataSource = dbReader.AsEnumerable().

雨的味道风的声音 2024-10-04 15:23:52

这是“DAAB 5 的事情”。

CodePlex 的“ctavares”表示:

“这是一个错误修复。在 Entlib 3.0 中,我们添加了对 System.TransactionScope 的支持。事实证明我们做错了,并在负载下的大型系统中导致了一些间歇性故障。以至于这个错误花费了一些大公司相当多的钱来解决这个问题,他们最终从他们的系统中完全删除了entlib,这个修复的一部分要求我们对我们拥有的数据库连接进行引用计数,这样我们就不会这样做。关闭它们,直到它们不再使用(这就是错误),因此我们需要包装数据读取器,以便我们可以正确检测读取器何时关闭并正确管理我们的连接。该错误实际上已发布在 codeplex 上。某处,但我忘记了工作项编号。”

来源:http://entlib.codeplex.com/discussions/ 211288

This is a "DAAB 5 thing".

According to "ctavares" at CodePlex:

"This was a bug fix. In Entlib 3.0, we added support for System.TransactionScope. It turns out we did it wrong, and caused some intermittent failures in large systems under load. To the point that the bug cost some large companies quite a bit of money in figuring out the problem, and they ended up removing entlib from their system completely. Part of this fix required that we do reference counting on database connections that we own so that we don't close them down until they're no longer used (which was the bug). As such, we needed to wrap data readers so we could properly detect when a reader was closed and manage our connections correctly. The bug was actually posted here on codeplex somewhere, but I forget the work item number. "

Source: http://entlib.codeplex.com/discussions/211288

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文