Pages

Tuesday, October 25, 2011

Do we need to pass a reference type argument to a method using REF keyword? - Part 02

Consider the following reference type variable x:
ArrayList x = new ArrayList()

Here, assume memory location of x is 2110 and it points to the memory location of the new object which can be 1110.

So, if you pass x variable to a method by reference without giving REF keyword, a copy of the reference, which resides in memory location 3110 is passed to the method with the value of 1110 which points to the same object.

But if you pass x variable to a method with REF keyword the original reference itself will be copied which in this case 2110.

For more info: when we should use REF keyword? - Part 01

Monday, October 24, 2011

How to give quotation mark in C# String?

Use backslash ahead of the string you need to quote
Ex: string quotationMark = "\" Hi! \"";

Sunday, October 23, 2011

How to fix System.BadImageFormatException in 64-bit OS?

If you try to refere a dll which has a file format which CLR does not support, you will get this exception. In 64 bit OS, this can happen due to dll is having some 32 bit parts (COM components etc.)  and it is being loaded as a 64 bit module.

To avoid that, you need to do the following:
  1. In Visual Studio, right click the project.
  2. In project properties, go to 'Build' tab
  3. In General section, select Platform target as x86 (default is 'Any CPU')
  4. Recompile the project and execute

Wednesday, October 19, 2011

Why you should not create indexes unnecessary?

Even though indexes improve performance in retrieval, they compromise the performance of inserts and updates.

Why adding a column is more costly than adding a record?

When you are adding a column, a schema lock is placed on the table, so that any connections to the table cannot be made during that time. So, if you can't afford any down time in your system [Always ON], this will definitely be a disadvantage.

Why we should not normalize data?

Since normalization has some well known advantages such as improved indexing, compact databases with less additional records and update performance improvement, I thought of writing about the disadvantages of normalization.

- More Joins - The more joins you use, it will cause more locks to the database, so we should avoid multiple joins when ever possible.

- Performance degrade in data retrieval (SELECT)

Because of that in data warehousing which is used for reporting and analysing, we normally use un-normalized form of data as number of retrievals are greater than inserts and updates.

Thursday, October 6, 2011

Advantage of having .mdf and .ldf files in two different disks

In SQL Server you can specify the path to database file (.mdf) and log file(.ldf).

When it comes to a server with high no. of transactions and full recovery mode, it is beneficial to have  these two paths in two different disks.

Then it will reduce Avg. Disk Queue Length, which is the average number of both read and write requests that were queued for the selected disk during the sample interval, thus resulting a significant improvement in terms of performance.

Simple facts about TempDB

  • When you create a temp table using # prefix that table will be created in TempDB.
  • TempDB is newly created when ever SQL Server is restarted.
  • Certain oprations cannot be performed on TempDB such as backup and restore, changing collation, changing schama name, drop the database etc.

SQL Server named instances: Why? Why not?

SQL Server can have one server instance per computer which is the default instance as well as multiple named instances with isolated databases and connections in the same server from SQL Server 2000 onwards. You can access named instances by server name\instance name (Ex: Galle\I01)

Why we need to have multiple named instances other than having one default instances per machine?
  • Maximum hardware utilization: Ex: If SQL your server version is designed to use only maximum 2GB RAM and your hardware supports 4GB RAM, you can optimize RAM usage by having two instances in the same server.
  • Isolation of databases which have no dependency over each other.
  • Better security seperation
Why we should not use them?

So the drawbacks of this approach are performance issues, difficulty to write cross database queries, using different ports for each instance , resource contention on memory and CPU.