Skip to main content

Posts

Showing posts from 2011

The Project Location is Not Trusted Dialog Box

Often due to backup issues, our desktop profile is setup to store all profile details (including documents) on  a share location. The benefit of this is two fold 1. It gives you roaming profile. You can logic from any desktop or even remotely, and you have access to all your personal documents 2. All your personal documents are backed up on a shared server. So if your desktop crashes or your laptop is stolen, still you have all your documents on the shared server. However as a developer using Visual Studio to develop web application, this presents some problems. By default the security policy on windows doesn't trust the files on a network share. So when you create or open a project from your My Documents/My Projects folder, Visual studio shows "The Project Location is Not Trusted" Dialog Box. Even worse if you try to debug the web application stored on a network share, you get an exception "An error occurred loading a configuration file: Failed to start monit

No SQL Databases

Recentely there has been lot of discussion about No SQL databases. Some see it as alternate to SQL database which means writing no SQL to query the database Hence No SQL. Another camp is opinion it is 'Not Only SQL' which basically means you can query the database in more than one way. These databases are also know as Document Databases as the data is stored as Documents (serialised as JSON objects) . There are three main leading open source Document databases MongoDB - http://www.mongodb.org / RavenDB - http://ravendb.net/ CouchDB - http://couchdb.apache.org/ Update: fourth contender, Amazon Simple DB : http://aws.amazon.com/simpledb/ RavenDB and CouchDB stores data as JSON objects while MongoDB uses a twist and stored data as Binary JSON (BSON) objects. Mostly the data is queries either through RestFUL API's using HTTP or through TCP/IP. These databases also support Indexes and Transactions. For transaction critical applications like banking or realtime syst

Difference between XML Serialization and Binary Serialization

XML Serialization Binary Serialization (Soap) No need of Serializable attribute on the class Need Serializable attribute Only public members are serialized All members are serializes unless specified as NonSerializable Class should have default public constructor and class itself should have public access. No need of default constructor or public access Namespace: System.XML,Serialization Namespace: System.Runtime.Serialization.Formatteres.Binary (.Soap) Outputfile is XML Outputfile is Binary or XML for SOAP formatter XMLSerializer need type of object to be serialized or deserialized No need to specify type of object to be serialized or deserialized. Support only IDesrializationCallback interface. No support for binary events. Binaryformatter support binary events. Soap formatter supports only IDeserializationCallback interface

Searching Unicode characters in Oracle table

Oracle implementation of Regular expression has no support for using hexadecimal code to search for Unicode characters. The only way to search for Unicode character is it use the character itself. Normally with Regular expression, you can use \x or \u followed by hexadecimal code to search for any character. E.g. \x20 will match space. But REGEXP_LIKE in Oracle does not support \x. You need to use unistr function to convert the code to equivalent character and then use it with REGEXP_LIKE. E.g. REGEXP_LIKE(source,'[' ||unistr('\0020')|| ']');

Handler error while running ASP.Net web application

If you are getting invalid handler error while running IIS application on local IIS, chances are that you have installed IIS after you installed .Net framework/Visual Studio. The problem is basically IIS by default is not configured to handle ASP.Net files. When you install the Framework, it configures IIS to handle all files for ASP.Net i.e files with extension .aspx, .asmx, .ascx etc. So to fix the error, login as local administrator on your machine. Go to Visual Studio command prompt from Program files. On the command prompt execute following command aspnet_regiis -i Wait for successful installation. Now try again running your application under IIS. This should solve the problem. More information about aspnet_regiis can be found at http://msdn.microsoft.com/en-us/library/k6h9cz8h%28v=VS.100%29.aspx

What is the difference between ASP.Net Development server and IIS?

When you are developing web application using .Net, you have three options for development web server. 1. Visual Studio (2008/2010/2011) has built in development server 2. You can install local IIS (XP Professional/Windows 7 Professional/Ultimate) 3. You have a dedicated development Windows server. You can use any of above three options if there are only few developers in your organisation. However in an enterprise level development, you may want to coordinate code deployment to common development server to avoid overwriting each other’s code. So that leaves with first two options. Option 1 is good if there are restrictions in your organisation on what are allowed to install and you are developing and testing pages at page level. However there are some drawbacks of using ASP.Net development server you must consider. 1. Security Context: By default ASP.Net development server runs in local users security context which has more privileges than a context in which a IIS server o

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 desktop application. Benefits of using stored procedure vs embedding SQL in application code ·          Using stored procedure can speed up enterprise level application development as one developer can focus on developing the database logic while other can focus on applica

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

How to pass and Reterive data from Thread - Part 3

To reterive data from a Thread, you need a delegate callback methdo. step1 : Decalre the delegate for the callback method public delegate void CallbackMethod(int anynum); This delegare define the signature of the funtion which will be called by the Thread. Step 2: Amend you call to accept delegate method while creating instance of the class private CallbackMethod _callback; public TypeSafe(int num, string msg, CallbackMethod callback) { _num = num; _msg = msg; _callback = callback; } Step 3: Amend the ThreadProc (procedure that will be running on the Thread) to make a call to callback method public void ThreadProc() { Console.WriteLine(_msg, _num); if (_callback != null) { _callback(_num + 100); } } Step 4: Create a static function which you want to be called by the Thread. Note this should match the signature of the delegate public static void ResultCallback(int n) { Console.WriteLine("result from callback is {0}", n); } Step 5: P

How to pass data to Thread - Part 2

Passing data to Thread using ParameterizedThreadStart  is the easiest way but not a type safe way as Thead.Start accepts any object. Alternative way is to encapsulate Thread procedure and data in a helper class and use the ThreadStart delegate to execute the Thread procedure. Make a note that you cannot return data from the Thread as there is no way to retrieve data from an asynchronous call. To retrieve data, you need callback method....which will look at part 3 of this article. Here is an example on how to pass data in a type safe way using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace ThreadTypeSafe { class Program { static void Main(string[] args) { TypeSafe ts = new TypeSafe(100, "This is message from a TypeSafe Thread with num as {0}"); Thread t1 = new Thread(ts.ThreadProc); t1.Start(); t1.Join();

How to pass parameter to a Thread?

When a managed thread is created, the method that executes on the thread is represented by a ThreadStart or ParameterizedThreadStart delegate that is passed to Thread constructor For E.g. //to call a method with no parameters, use ThreadStart Thread t1 = new Thread(new ThreadStart(MyMethod)); //to call a method with parametets, use ParameterizedThreadStart Thread t1 = new Thread(new ParameterizedThreadStart(MyMethod)); To make it easy, Visual Basic and C# allow a short cut //short cut method Thread t1 = new Thread(MyMethod); Now the compiler works out which delegate constructor to use based on definition of MyMethod. To pass a parameter, similpy pass a value when you call Start on the Thread t1.Start(14); ///will pass 14 to MyMethod t1.Start("my message"); ///wiil pass "my message" to MyMethod //definition of MyMethod public static void MyMethod(object data) { //cast data to correct type and use data value //for e.g. output as string Co

Immutable String and Performance

String of the type System.String is immutable in the .Net Framework. That means any change to a String causes the runtime to create a new string and abandon the old one. Guess how many string references following code will create? //c# String s; s= "one"; //"one" s += " two"; //"one two" s += " three"; //"one two three" s += " four"; //"one two three four" Console.WriteLine(s); If you guessed it four, you are right. Most developers think this is only one string. After running the code only the last string has a reference, the other three are disposed off during garbage collection. Avoiding these kind of temporary string helps avoiding unnecessary garbage collection and hence helps improve performance. There are several ways to avoid temporary string 1. Use the Concat, Join or Format method of the String Class to join multiple items into a single statment. 2. Use StringBuilder Cla