負荷がかかっているサイトでのLINQ to SQLエラー(> 30ユーザー)

最近では、LINQ to SQLの使用を開始しました。サイトを読み込むと、この種のエラーに気づき始めました。
韓国のランダムのスタイルで表示されるもの:

オプション1)InvalidCastException
オプション2)DataReaderが閉じられています
オプション3)SQL Serverは、MARSに関連するエラーも生成し、接続を切断します


通常、クラスはLINQを使用して作業を行います:

using System.Linq;
using Kushatpodano.Ru.Models;

namespace Kushatpodano.Ru.Classes.BusinessLayer
{
public class CustomPages
{
private readonly KushDBDataContext context = new KushDBDataContext();

public static string PageText( string ActionResult)
{
return ( from p in context.CustomPages
where p.ActionResult == ActionResult
select p).Single().PageText;
}

public static string PageTitle( string ActionResult)
{
return ( from p in context.CustomPages
where p.ActionResult == ActionResult
select p).Single().PageTitle;
}
}
}


* This source code was highlighted with Source Code Highlighter .


Googleでこれらのエラーを検索しても実質的に何も得られませんでしたが、昨日、このエラーでフォーラムで別のトピックに遭遇しました。この方法でクラスを書き換えた後、バイパス方法が書かれていました-ホスティング業者はロードを停止しましたが、LINQはうまくいっていました:

using System.Linq;
using Kushatpodano.Ru.Models;

namespace Kushatpodano.Ru.Classes.BusinessLayer
{
public class CustomPages
{
public static string PageText( string ActionResult)
{
string PageText;
using (KushDBDataContext context = new KushDBDataContext())
{
PageText = ( from p in context.CustomPages
where p.ActionResult == ActionResult
select p).Single().PageText;
}

return PageText;
}

public static string PageTitle( string ActionResult)
{
string PageTitle;
using (KushDBDataContext context = new KushDBDataContext())
{
PageTitle = ( from p in context.CustomPages
where p.ActionResult == ActionResult
select p).Single().PageTitle;
}

return PageTitle;
}
}
}


* This source code was highlighted with Source Code Highlighter .


呼び出しのブロックごとに、新しいコンテキストを作成および破棄する必要があります。
通常のSqlConnectionを使用する場合と同様です。

Source: https://habr.com/ru/post/J67207/


All Articles