Question : LINQ to SQL Performance Issues

Ive deployed a .NET 3.5 web application in C# recently with a lot of LINQ to SQL methods in place for the data access layer. In development the app ran perfectly well, but now in production its very sluggish at times, and Im getting a lot of unusual errors in the Event Log. Some examples of the errors Im getting are as follows:


Event Type:        Warning
Event Source:    ASP.NET 2.0.50727.0
Event Category:                Web Event
Event ID:              1309
Date:                     26/08/2008
Time:                     13:26:08
User:                     N/A
Computer:          NEW-SERVER5
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 26/08/2008 13:26:08
Event time (UTC): 26/08/2008 12:26:08
Event ID: e48573d670e54a338b446cdf0ea8c795
Event sequence: 11257
Event occurrence: 16
Event detail code: 0
 
Application information:
    Application domain: /LM/W3SVC/1132683740/Root-1-128642241039958706
    Trust level: Full
    Application Virtual Path: /
    Application Path: C:\inetpub\wwwroot\mysite\
    Machine name: NEW-SERVER5
 
Process information:
    Process ID: 11240
    Process name: w3wp.exe
    Account name: NT AUTHORITY\NETWORK SERVICE
 
Exception information:
    Exception type: InvalidCastException
    Exception message: Unable to cast object of type 'System.Int32' to type 'System.String'.
 
Request information:
    Request URL: http://myurlhere
    Request path: /mypage.aspx
    User host address: 127.0.0.1
    User:  
    Is authenticated: False
    Authentication Type:  
    Thread account name: NT AUTHORITY\NETWORK SERVICE
 
Thread information:
    Thread ID: 34
    Thread account name: NT AUTHORITY\NETWORK SERVICE
    Is impersonating: False
    Stack trace:    at System.Data.SqlClient.SqlBuffer.get_String()
   at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)
   at Read_<>f__AnonymousType0`1(ObjectMaterializer`1 )
   at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
   at events.BindFilterOptions()
   at events.Page_Load(Object sender, EventArgs e)
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
 
Custom event details:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.


Event Type:        Warning
Event Source:    ASP.NET 2.0.50727.0
Event Category:                Web Event
Event ID:              1309
Date:                     26/08/2008
Time:                     12:44:24
User:                     N/A
Computer:          NEW-SERVER5
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 26/08/2008 12:44:24
Event time (UTC): 26/08/2008 11:44:24
Event ID: 36711c0e7ea74344b68a5a9dd29dfa62
Event sequence: 1914
Event occurrence: 3
Event detail code: 0
 
Application information:
    Application domain: /LM/W3SVC/1132683740/Root-1-128642241039958706
    Trust level: Full
    Application Virtual Path: /
    Application Path: C:\inetpub\wwwroot\mysite\
    Machine name: NEW-SERVER5
 
Process information:
    Process ID: 11240
    Process name: w3wp.exe
    Account name: NT AUTHORITY\NETWORK SERVICE
 
Exception information:
    Exception type: InvalidOperationException
    Exception message: Both DataSource and DataSourceID are defined on 'lvPhrases'.  Remove one definition.
 
Request information:
    Request URL: http://mysite
    Request path: /mypage.aspx
    User host address: 127.0.0.1
    User:  
    Is authenticated: False
    Authentication Type:  
    Thread account name: NT AUTHORITY\NETWORK SERVICE
 
Thread information:
    Thread ID: 7
    Thread account name: NT AUTHORITY\NETWORK SERVICE
    Is impersonating: False
    Stack trace:    at System.Web.UI.WebControls.DataBoundControl.ConnectToDataSourceView()
   at System.Web.UI.WebControls.DataBoundControl.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
 
Custom event details:

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Answer : LINQ to SQL Performance Issues

Hi billy_boy;

1. "Unable to cast object of type 'System.Int32' to type 'System.String'."

Make sure that the table mapping are correct.


2. "Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. "

This is that the program has not received a response back from the query sent out. Could be that the server has a heavy load or network traffic. You may try to increase the response time out.

3. "Both DataSource and DataSourceID are defined on 'lvPhrases'.  Remove one definition."

Use DataSource or DataSourceID but do not use both on the same control. From Microsoft documentation:
Use the DataSourceID property to access the ID property of the data source control that the data listing control should use to retrieve its data source. The data source control referenced by the DataSourceID property can be any control that implements the IDataSource interface. The data source control must exist either in the same naming container as the data listing control that references it, or in a parent control of the data listing control. When you specify a value for this property, the data listing control automatically binds to the specified data source control. You do not need to write code that explicitly calls the DataBind method.

Alternately, you can use the DataSource property to specify the source of values to bind to a data listing control. The data source must be an object that implements the System.Collections.IEnumerable interface (such as System.Data.DataView, System.Collections.ArrayList, or System.Collections.Hashtable) or the IListSource interface to bind to a control derived from the BaseDataList class. When you set the DataSource property, you must manually write the code to perform data binding.

If values are specified for both the DataSource property and the DataSourceID property, ASP.NET is not able to resolve the data source and an System.Web.HttpException exception is thrown.
 
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedatalist.datasourceid.aspx

Fernando
Random Solutions  
 
programming4us programming4us