July 3, 2015

Asp.Net - UpdatePanel Time Out

I was working with an asp.net applcation and one of the pages was producing errors. After going through the error, I realise it was failing with a timeout error. So, I went ahead and increased the timeout value for both WCF service and also the SqlCommand that's being called by the Wcf service, however, even though there was no exception, the data was not displaying on the site.

So, to test the issue, I started inspecting the issue in Chrome and under the Network tab, there was an error "Sys.WebForms.PageRequestManagerTimeoutException", which meant some kind of error with the UpdatePanel. After this, I increased the timeout value for the UpdatePanel by setting the "AsyncPostBackTimeout" property on "ScriptManager" and then it got fixed.

Blogger Tricks

June 24, 2015

I have this Sql table setup in Sql Server that contains a XML field and I need to count the number of times a xml node appears in the xml. In practice, it could be the table contains user data and the xml contains a list of cities the user has visited and we need to find out how many cities the user has visited.

June 19, 2015

I have sometimes seen WCF services that times out. The easiest way to fix it is to increase the timeout value within the config file. Here is an example of this can be done.

  1. <binding name="WSHttpBinding_ILoanService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">  
  2. </binding>

Okay, so there are four different timeouts - what do they mean.

How to Increase SQL Command Timeout

Sometimes I have seen while running a sql script from .NET code that the Sql Command times out. The solution is simple - we just need to increase the timeout. However, we should really think on why the timeout increase is needed and whether we should change the query - like, by reducing the number of rows returned - to minimise the time taken.

Before starting the discussion, what is Sql Command? It's a call to the database to get data or to update data. We can either directly execute the sql script or call a stored procedure by passing in the relevant parameters. In case, we figure we cannot change the sql query and our only option is to increase the timeout, then we can write the following code.

I was running an application using Visual Studio and for not so apparent reason the web service was not working. Since I was debugging the web site connecting to a web service within visual studio - it was not apparent as to why it was failing. When I started debugging the web service, I figured it resulting in an error - Memory gates checking failed because the free memory (296964096 bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element..

Practically there are no differences between int and System.Int32 (except while using enums). C# allows for certain aliases and it is one of those. Both int and System.Int32 are compiled to System.Int32 in the Intermediate Language (IL). C# contains a number of aliases that allows for quick typing of the variable types. Here is a full list of the aliases.

May 22, 2015

Recently, I had to login to a SQL Server to get some data but the pain was I had to login to remote desktop using a different windows username and then opening Sql Server Management Studio and then opening connection to the Sql Server in a different server. I was thinking this is just crazy and I would simply just want to connect to the sql server using my local Sql Server Management Studio.

May 18, 2015

C# Different ways to create a string

Strings, in C#, represents text as a series of Unicode characters. A string can be referenced as both "string" and "String" - string is basically an alias of System.String.  It can be created in a number of ways. In the simplest form, it can just be assigned or alternatively it can be created using the String's constructors. String, like other objects in .NET, can be assigned to null. Strings might look like and can be used like other variables like int or double but one important characteristics is that it is immutable - that is, once a String is created, it cannot be changed (so, when a string variable is re-assigned, behind the scenes, a new string is created and assigned to the variable).

The main difference between nvarchar and varchar column is in the character set of data that it can store. Varchar is single byte whereas nvarchar is double-byte and therefore nvarchar can store Unicode characters while varchar cannot.

May 15, 2015

To escape a single quote in Sql Server, use two single quotes. Note, don't use a double quote.

For example, the following SQL Script will give error.

Reference: Shahed Kazi at AspNetify.com