Skip to main content

Posts

When to implement IDisposable?

In .Net, garbage collector is very good at cleaning up managed resources. Managed resources are object implemented using .Net framework and something that the Garbage collector is aware of. Unmanaged resource is anything that is implemented outside .Net framework and Garbage collector has no information about it. The combination of Destructor and Dispose can be used to release unmanaged resources for e.g open files or database connection. If you are not using any unmanaged resource, there is no need to implement IDisposable. Garbage collector will take care of release the unused objects and freeing up the memory.

What is Default search order for views in MVC 3?

By Default IIS will search for a view based on the Action method name in following orde ~/Views/ / .aspx ~/Views/ / .ascx ~/Views/Shared/ .aspx ~/Views/Shared/ .ascx ~/Views/ / .cshtml ~/Views/ / . cshtml ~/Views/Shared/ . cshtml ~/Views/Shared/ . Cshtml Note: It searches for a view than a partial view. Also it searches for a aspx page(ASPX rendering engine) first than a cshtml page(Razor engine)

How to produce environment specific config file?

A typical software development life cycle involves 3 environments 1. Development 2. Staging/Testing 3. Production/Live Often while developing web application, you need to reconfigure the web.config file so that it has correct setting (e.g. database, debug flags, error handling etc) depending on the environment. I have seen project horrors when development settings have gone live or development servers are pointing to live servers and users have accidentally deleted live data!! I think Microsoft must have realized this over years and have finally introduced a solution in VS2010. It is a very simple but powerful idea: you have one config file but apply transformation when you build the project for each environment. You can read the complete details here: http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx

System.Configuration in .Net Framework 2 onwards - part 2

Some people asked why do you have to explicitly add  reference to System.Configuration.dll assembly? Why can't Visual Studio work out latest version based on the Target framework? Also why is this still the case in .Net Framwork 4.0? here is the secret..... In .Net 1.1, System.Configuration namespace was included in System.dll assembly. So they had to keep this namespace in all future release of .Net framework to make it backward compatible. From .Net 2.0 onwards, Microsoft created a new assembly System.Configuration.dll which includes the namespace System.Configuration. This namespace includes all new functionality. When you create a new project in Visual Studio (any version), by default it adds reference to System.dl. Hence when you just reference System.Configuration namespace using "Using or Imports", it references the namespace within System.dll. Hence you get old functionality. By adding a reference to System.Configuration.dll, now you have System.Config...

System.Configuration in .Net Framework 2 onwards

Often application need custom configuration section. System.Configuration namespace includes classes for reading and writing configuration settings. There is a slight difference in how you use this namespace depending on the Framework version you are using Prior to .Net Framework 2.0, the .Net Framework included System.Configuration namespace, but that version of the namespace is now outdated. If you simply add the System.configuration namespace to your project (using in C#), your application references the outdated namespace. To refer to the updated namespace, follow these steps 1. In VS, open the project that requires System.Configuration namespace. 2. Click on the Project menu and then click Add Reference 3. On the .Net tab, Select System.Configuration as shown in following figure, and click OK 4. Now add the System.Configuration namespace to your project normally using Imports (in VB) or using (in C#) and your application will reference the correct version of the namespa...

Use of Oracle Stored Procedures

Introduction: This paper discusses the pros and cons of using Oracle stored procedure for encapsulating SQL. We will also look at the option of storing SQL within the application code. We will use following benchmarks to compare the two 1.        Ease of enterprise level development 2.        Separation of code 3.        Maintenance/support 4.        Testing 5.        Debugging 6.        Performance 7.        Security 8.        Developers skill set 9.        Transaction (Complex business Logic) For sake of simplicity, the term ‘Stored Procedure’ or ‘Stored Function’ are interchangeable. ‘Package’ is a grouping of related elements. Application code can be a VB, C# or PHP code for a web or desk...

ODP.Net issue for 10.2.0.4 driver

Please note that Windows 7 has a new Oracle Client (10.2.0.4). In most cases this should be simply the case of removing the existing reference to Oracle.DataAccess from your application and adding a new one from new client folder. However in one case, we came across rather an unusal problem. We call stored functions from a windows application which return Integer type value. Please note we are using RETURN type values not OUT type parameters as this a Function. Here is the C# code. /****************************/ OracleCommand cmd = new OracleCommand("DoesDataItemExist", oraCn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("RETURN_VALUE", OracleDbType.Int16, ParameterDirection.ReturnValue); cmd.Parameters.Add("p_ID", id); cmd.Parameters.Add("p_YEAR", year); oraCn.Open(); cmd.ExecuteNonQuery(); Int16 retVal = (Int16)cmd.Parameters["RETURN_VALUE"].Value; oraCn.Close(); return retVal > 0...