小编DA_*_*rog的帖子

抛出了类型'System.OutOfMemoryException'的异常.C#使用IDataReader时

我有一个应用程序,我必须从DB获取大量数据.由于它未能获得所有这些行(它接近2,000,000行...),我在中断时将其剪切,并且每次执行sql查询时每次只获得200,000行.

我使用DataTable输入所有数据(意思是 - 所有2,000,000行应该在那里).

前几次运行很好.然后它以OutOfMemoryException失败.

我的代码如下:

private static void RunQueryAndAddToDT(string sql, string lastRowID, SqlConnection conn, DataTable dt, int prevRowCount)
    {
        if (string.IsNullOrEmpty(sql))
        {
            sql = generateSqlQuery(lastRowID);
        }

        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }

        using (IDbCommand cmd2 = conn.CreateCommand())
        {
            cmd2.CommandType = CommandType.Text;
            cmd2.CommandText = sql;
            cmd2.CommandTimeout = 0;

            using (IDataReader reader = cmd2.ExecuteReader())
            {
                while (reader.Read())
                {
                    DataRow row = dt.NewRow();
                    row["RowID"] = reader["RowID"].ToString();
                    row["MyCol"] = reader["MyCol"].ToString();
                    ... //In one of these rows it returns the exception.

                    dt.Rows.Add(row);
                } …
Run Code Online (Sandbox Code Playgroud)

c# sql exception datareader using-statement

7
推荐指数
2
解决办法
3万
查看次数

获取thead下的所有标签

我有一个简单的html表,其中包含thead,tbody和tfoot.我想在thead中选择使用javascript或jquery所有th标签.到目前为止,我找到了一种方法来获得表中的所有内容或thead本身.

我的桌子:

        <table id="MyTbl" class="display">
                <thead>
                    <tr>
                        <th>
                            ID
                        </th>
                        <th>
                            Name
                        </th>
                        <th>
                            Desc
                        </th>
                    </tr>
                </thead>
                <tbody id="MyTableBody">
                </tbody>
                <tfoot>
                    <tr height="27px">
                        <th class="TDHMain">
                            FILTER ID
                        </th>
                        <th class="TDHMain">
                            FILTER NAME
                        </th>
                        <th class="TDHMain">
                            FILTER DESC
                        </th>
                    </tr>
                </tfoot>
            </table>
Run Code Online (Sandbox Code Playgroud)

我的javascript:

var table = document.getElementById('MyTbl');
var tableHeader = table.getElementsByTagName('thead');
var headers = tableHeader.getElementsByTagName('th'); //This one doesn't work. No such a method for the thead tag
Run Code Online (Sandbox Code Playgroud)

我也尝试了以下代码:

headers = $('#MyTbl').find('thead > th').get();
Run Code Online (Sandbox Code Playgroud)

但结果我真的不明白如何使用它...它不是一个数组,因此我得到的头对象没有foreach函数,我真的找不到一种方法来获取数据.

反正是否只能获得表格中的元素?

谢谢

javascript jquery html-table

3
推荐指数
1
解决办法
1万
查看次数

带有 ClientCredentials 属性的 CreateChannel

我对 WCF 很陌生,并尝试使用自定义用户名和密码创建 WCF 服务。我知道我应该将用户名和密码设置为代理的 ClientCredentials,但出于某种原因,我没有这样的属性......

我认为这与我的合同有关,所以这里是:

我的合约代码:

namespace Contracts
{    
    [ServiceContract]
    public interface ICalc
    {
        [OperationContract]
        CalcResponse Add(double x, double y);

        [OperationContract]
        CalcResponse Substract(double x, double y);

        [OperationContract]
        CalcResponse Multiply(double x, double y);

        [OperationContract]
        CalcResponse Divide(double x, double y);
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的客户中,我尝试做的就是:

ChannelFactory<ICalc> channel = new ChannelFactory<ICalc>("calcEndpoint");
ICalc proxy = channel.CreateChannel();

proxy.ClientCredentials.UserName.UserName = "USER";
proxy.ClientCredentials.UserName.Password = "PASSWORD";
Run Code Online (Sandbox Code Playgroud)

但是我的代理没有 ClientCredentials 属性

更新: 我遇到了一些导致其他错误的问题。当我解决它们时,出现了一个新错误:

套接字连接已中止。这可能是由于处理您的消息时出错或远程主机超过接收超时,或底层网络资源问题引起的。

我的超时时间在客户端和服务器中都设置为 5 分钟。不到一分钟,我收到此错误...

这是我更新的代码:

ChannelFactory<ICalc> channel = new ChannelFactory<ICalc>("calcEndpoint");

var defaultCredentials = channel.Endpoint.Behaviors.Find<ClientCredentials>();
channel.Endpoint.Behaviors.Remove(defaultCredentials);

ClientCredentials loginCredentials …
Run Code Online (Sandbox Code Playgroud)

c# wcf contract client-certificates

3
推荐指数
1
解决办法
5900
查看次数