Committed Developer
Sunday, April 24, 2011
New data types in SQL 2008
1. Geographic
2. Date
3. Datetime2
4.Time
5. Timeoffset
6. HierarchyId
refer: http://www.simple-talk.com/sql/learn-sql-server/sql-server-2008-the-new-data-types/
C# 3.0 introduces several new features. Few of them are
1. Implicitly types local variable
var a = 10;
2. Extension methods
Built in types can be extended using extension methods.
like ToInt32(string s) can be added to String data type. All the extension methods should be declared as static methods
3. Lambda expression:
More sophisticated anonymous methods.
Anonymous methods requires parameter types should be explicitly stated, where as lambda expressions can infer the parameter types if omitted
4. Object and collection initializers
customer c = new customer { name="custname", id = "1234"};
List
5. Anonymous Types
var a = new { a="10", b = "100"}
6. Implicitly types arrays
var a = new[] {1,2,3,4};
7. Automatically Implemented properties
public int x {get;set;}
8. Query Expression (using from keyword)
Refer: http://msdn.microsoft.com/en-us/library/bb308966.aspx#csharp3.0overview_topic22
Sunday, June 13, 2010
Different Hosting models in WCF
The following are the different hosting models available for wcf services
I. Self hosting in Managed application
. In a Console application or windows application or WPF application
Scenario & advantages/disadvantages:
Generally whole testing the services.
Not used for production deployment.
II. Windows Services
. WCF services can be hosted in Managed Windows Services .
Scenario & advantages/disadvantages:
Good for long running services
Can be used as a production deployment option.
Life time is controlled by service control manager
Not message activated, means service-host needs to be created in the app domain in order to server the incoming requests for wcf services.
III. Internet Information Server
. Most robust option for production deployment.
. Message based activation supported. IIS takes care of having the servicehost created in the process/app-domain
. Process recycling is supported.
. IIS 5, IIS 6 support only http protocol
. IIS 7 supports all http and tcp protocols.
IV. WAS (Windows Activation Services)
. Provides Message based activation, process recycling etc (what IIS provided to http based wcf services) for all tcp based wcf services along with http protocol also.
. IIS is not required.
Thursday, June 3, 2010
Object oriented concepts
- When do you say a programming language is Object oriented?
- A language is called object oriented language if it satisfies the following object oriented concepts (OOPS concepts)
i. Abstraction: binding data and methods (behavior) together. Example: Class binds data and methods
ii. Encapsulation: Hiding the data. Access specifiers like public, protected, private, internal are access specifiers
iii. Inheritance: A concept used to create a new class from an existing class there by get the behavior and properties of the base/parent class
iv. Polymorphism: Behaving differently at run time based on the object the behavior is invoked. There are 3 ways we can have polymorphic behavior:
1. Method overriding
2. Method Overloading
3. Operator overloading
- Example for Inheritance
- Animal is a base class
- Tiger, Cow are derived classes
- Shout() method on cow says baaa…..
- Shout() method on Tiger says grrrrr…..
- Both are animals but have different characteristics.
- Example for polymorphism
- Same as above
- What is method overriding?
- Overriding means giving a defining the base class method again in the derived class. The base class method must be declared as virtual
- In the derived class override (C#) key word should be used to override the method.
- What is method overloading?
- A method is said to be overloaded when the method signature is different with same name. A signature is different if one of the following is true
i. Number of parameters are different
ii. Sequence of parameters different
iii. Data type of any one parameter is different
- Two methods having different return types will not be considered as overloaded
- What is the difference between class and an object?
- Object is an instance of a class
- Class represents a classification, or class is an abstract representation of an object or group or a thing
- What is the difference between Abstract class and Interface?
- Abstract class should have at least one abstract method.
- Abstract class can contain member variables
- Abstract class can define methods
- Interface cannot have member variables and all the methods should be abstract
- An abstract method is nothing but a method declaration without method definition
- What is the difference between method declaration and definition?
- Declaration means just having the method signature. Like
i. {Return Type} {MethodName} ( {parameters}
- Definition means defining the method.
- What is initialization?
- Means giving an initial value at the time of declaring the variable
- What is the difference between class and a struct?
- Class is a reference type and will be stored on heap.
- Struct is a value type and will be stored on stack
- Class can inherit other classes and implement interface
- Struct cannot inherit but can implement interfaces
- What is the significance of this keyword?
- Each object has a reference “this” which points to itself.
- Can be used to refer to the current object.
- Also be used by one constructor to explicitly invoke another constructor of the same class.
- In which sequence constructors will be called in case of derived classes?
- First base classes constructors will be called then derived class constructors will be called
- In which sequence destructors will be called in case of derived classes?
- First derived classes destructors will be called then base class destructors will be called
- What are Static Binding and Dynamic Binding?
- Static binding means giving a type to a variable at compile time. Runtime binding mans giving a type to the variable at runtime.
- Ex: int x – static biding, object x; x = “some string” --runtime binding
Tuesday, March 30, 2010
Working with MSDTC and System.Transactions in .NET 2.0
I have noticed that if we use TransactionScope, then with SQL 2000 the transaction is automatically enlisted in the MSDTC even if we are using single data base.The code works fine if we deply the SQL 2000 on Win2K server, because MSDTC automatically be started if the code runs. Problem comes only when MSDTC is disabled on this Win2k machine.
This is the exception that occurs:
System.Transactions.TransactionAbortedException: The transaction has aborted. ---> System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed. ---> System.Runtime.InteropServices.COMException (0x8004D01B): Exception from HRESULT: 0x8004D01B at System.Transactions.Oletx.IDtcProxyShimFactory.ConnectToProxy(String nodeName, Guid resourceManagerIdentifier, IntPtr managedIdentifier, Boolean& nodeNameMatches, UInt32& whereaboutsSize, CoTaskMemHandle& whereaboutsBuffer, IResourceManagerShim& resourceManagerShim) at System.Transactions.Oletx.DtcTransactionManager.Initialize() ---
The above problem occurs if we deploy the SQL 2000 on win2k3 server, because by default all security settings are disabled on the MSDTC on Win2K3. So in order to make it work, we need to configure MSDTC on the Win2k3 server to accept remote requests and other stuff.
Go to Control panel -> Adminstrative Services -> Component Services
Component Services -> Computers -> My Computer
go to properties of MyComputer, select MSDTC TAB
click on 'Security Configuration'
Make sure you check "Network DTC Access", "Allow Remote Client","Allow Inbound/Outbound", "Enable TIP"
Now the code should run fine. Else try after restaring the machine.
Note:
This behavior is different if we use SQL 2005 as SQL 2005 promotes the transaction to use MSDTC only when it's required.
Issues with reading Output, Return values from Stored Procedure
Output or ReturnValues from the storedprocedure cannot be retrieved from the command object unless we completely traverse through the Reader.
for more info check: http://support.microsoft.com/?id=308051
Thanks,
-Krish...
Create .EML or .MSG files programmatically using C#.
Problem statement:
The requirement is to send emails to out side world with attachments. The email can contain more than one email as attachment and those attachments should look like as new email message is actually being attached to the outgoing email.
Possible soultions identified:
1. As we need to have email as attachment, so having other kinds of attachments ruled out.
2. Possible option for the email attachments are either .eml or .msg.
.MSG file can be created using Microsoft.Interop.xxx assembly and attach to the email and remember .msg is a Microsoft propriatory standard.
Courtesy : For more information: http://weblogs.asp.net/darrensim/archive/2008/06/29/creating-an-outlook-message-file-with-c.aspx
.eml is the global standard. But how can we create .eml file? This can be done by digging through the System.Net.mail.MailMessage.Send() method.
A very good article is available in codeproject : http://www.codeproject.com/kb/ip/smtpclientext.aspx?msg=2876295