Is mixing ADO.NET and LINQ-TO-SQL bad? Data layer not working

UPDATE

As Matthias notes below, this exact problem has been reported and resolved here: ASP.NET-MVC (IIS6) error with high traffic: the specified cast is not valid

ORIGINAL MAIL

This may be too specific a debugging problem to be posted here, but I still post it in the hope that it will work out a solution that others find useful.

I have a web application that runs under moderate load - maybe 5 requests per second. It has older code that talks to Sql via ADO.NET + DataReaders and has been using the same technique for at least five years without any problems. It also has some new code using LINQ-to-SQL. Both methods use the same connection string to maximize reuse of the connection pool.

Recently, I have been experiencing very strange behavior described by these symptoms:

  • Everything will work fine throughout the day, and then suddenly every call (or almost every call) to the data layer (both ADO.NET and LINQ) returns data that cannot be analyzed using my code - Receive exceptions like "Impossible cast an object of type "System.Int32" to type "System.String". " or "The sequence contains no elements" or "IndexOutOfRangeException" or "An invalid attempt to call Read when the reader is closed."

  • Interestingly, I never get exceptions from SqlCommand.ExecuteReader () or DataReader.Read () - exceptions occur only when trying to parse the returned IDataRecord.

  • I can solve the problem temporarily by restarting Sql or IIS. After a few hours he returns again.

  • , 3 . , 100.

  • , Sql IIS.

  • 9 .

  • , ECC DIMM.

  • , ADO.NET, .

  • Management Studio, .

ADO.NET:

using (var dbConn = Database.Connection) // gets already-open connection
{
  var cmd = new SqlCommand("GetData", dbConn);
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Parameters.AddWithValue("@id", id);

  SomeDataObject dataObject = null;

  var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection | CommandBehavior.SingleRow);

  if (dr.Read())
    dataObject = new SomeDataObject(dr);

  dr.Close();

  return dataObject;
}

: , ADO.NET LINQ , , - ?

: - , ? , ?

+3
2

UPDATE

- , , -,

ASP.NET-MVC (IIS6) : .

ATLE

linq-to-sql . MVC - Storefront , , . , , , , .

, , db-.

: jmeter 5 , (20, ). , .

, : , Jmeter ( ASP.NET, ASP.NET MVC) .

+1

20+ 5 - . 100 10 .

? ?

, . , LINQ to SQL, ADO.NET. , LINQ to SQL, ..

- ADO.NET LINQ ? ADO.NET, , ..? LINQ , .

, , " ", , .

+2

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


All Articles