Friday, December 21, 2012

The underlying provider failed on Open Error in Entity Framework Transactions


Error:
The underlying provider failed on Open
MSDTC on server 'XXXXX\\SQLEXPRESS' is unavailable."   at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)\r\n   at System.Data.EntityClient.EntityConnection.Open()\r\n   at System.Data.Objects.ObjectContext.EnsureConnection()\r\n   at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)\r\n   at System.Data.Objects.ObjectContext.SaveChanges()\r\n  

Cause:
The error The underlying provider failed on Open is thrown while performing a transactional update using Entity Framework, if the MSDTC - Distributed Transaction Coordinator service is not started.

Resolution:

Transactions in Entity Framework with DbTransaction.


In many real time scenarios we will have to use transactions to perform Atomic operation, i.e a set so statements should get executed completely or get rollback completely. A typical example of a transactions in the Bank account example, debit X amount from account A and credit the X amount to account B, now if there is an issue between debiting from account A and crediting to account B the whole operation should be cancelled.

In this post we shall see on how to perform transactions using Entity Framework and DbTransaction. Unlike the TransactionScope which needs the MSDTC - Distributed Transaction Coordinator service to be running, DbTransaction will work even if the service is not running.

In this post we will do 2 operations insert a row in the Bugs table and insert a row in the Comments table in a single transaction.

Thursday, December 20, 2012

Transactions in Entity Framework with TranscationScope.


In many real time scenarios we will have to use transactions to perform Atomic operation, i.e a set so statements should get executed completely or get rollback completely. A typical example of a transactions in the Bank account example, debit X amount from account A and credit the X amount to account B, now if there is an issue between debiting from account A and crediting to account B the whole operation should be cancelled.

In this post we shall see on how to perform transactions using Entity Framework and TransactionScope. To make use of the TransactionScope we need to make sure that the MSDTC - Distributed Transaction Coordinator service is running. If the service is not running then the code will throw the following error.
The underlying provider failed on Open

In this post we will do 2 operations update the Bugs table and insert a row in the Comments table in a single transaction.

TranscationScope Vs DbTransaction


A transaction is an atomic operation, i.e a set so statements should get executed completely or get rollback completely. A typical example of a transactions in the Bank account example, debit X amount from account A and credit the X amount to account B, now if there is an issue between debiting from account A and crediting to account B the whole operation should be cancelled.

Transactions in the Entity Framework can be performed using 2 ways, using TranscationScope or by using DbTransaction. In this post we shall compare the 2 approaches.

Transactions in Entity Framework


A transaction is an atomic operation, i.e a set so statements should get executed completely or get rollback completely. A typical example of a transactions in the Bank account example, debit X amount from account A and credit the X amount to account B, now if there is an issue between debiting from account A and crediting to account B the whole operation should be cancelled.

Transactions in the Entity Framework can be performed using 2 ways, using TranscationScope or by using DbTransaction. In this post we shall compare the 2 approaches.

Tuesday, December 11, 2012

What's New in ASP.NET MVC4

The feature additions in Asp.Net MVC4 are relatively less when compared to the MVC2 – MVC3 upgrade. Asp.Net MVC4 mainly focuses on mobile web development, in addition it adds a few features to the existing Web application projects.


1. Includes support for Asp.Net Web API

What's New in ASP.NET MVC3

Asp.Net MVC3 has brought in a whole lot of features, which help in improved productivity, performance, scalability and security. 


Asp.Net MVC3 is the successor of Asp.Net MVC2, it requires .Net Framework 4.0 or higher and is compatible with
Visual Studio 2010 or higher. We shall see some of the key feature additions to Asp.Net MVC3 in this post.

1. Introduction of Razor view engine

Wednesday, December 5, 2012

Asp.Net MVC Application Project Templates

Visual Studio 2008/2010, provides 2 templates for creating Asp.Net MVC Applications.
          Asp.Net MVC Web Application
          Asp.Net MVC Empty Web Application

Asp.Net MVC Web Application

The Asp.Net MVC Web Application template creates a project with a set of pre-defined files which are ready to run, this template will give a sample set of files on top of which the users can create additional files.

Asp.net MVC Vs Web Farms Application

Asp.Net MVC is not a replacement for the Web Forms model of Asp.net application, each has its own advantages and disadvantages, it is up to the user to decide on which model to user based on the requirements and other factors.

In this post we shall compare the features of Asp.Net MVC Applications and Web Farms Application

ASP.NET MVC - The Controller

As the name suggests the Controller is the one which controls the execution of the entire application, all requests to the applications are handled by the controller, once the controller receives the request it decided the model to be called, and the View to be invoked to render the output to the Browser.

A Model is a .vb or .cs class, Controller classes should end with the word “Controller” example EmployeeController, DepartmentController etc. The controller contains a set of Action methods, each of which is mapped to a specific request from the user.

ASP.NET MVC - The View

The View is the UI part of the MVC Architecture, the View is fully responsible for what the user sees in the browser, all UI aspects like controls, color, style, formatting etc are taken care of by the View.
The View defines the style and formatting aspects of the display and embeds the data provided by the model to produce a page which has meaningful information.

A View is an .aspx file, The Name of the View should match the name of the function in the controller which handles the View. For example a view with the name LogOn should have a matching method in the controller which handles requests for this View.

The Controller receives the request from the user and invokes the corresponding view, the view in turn makes use of the data from the Model and renders the page to the user in the browser.

ASP.NET MVC - The Model

The Model represents the data engine of the MVC architecture, the Model holds the data to be rendered to the UI, the View makes use of the data in the model and binds it appropriately in the Page to display data in the browser. The Model is also responsible for retrieving the data from and saving the data back to the underlying database.

A Model is a .vb or .cs class, Model classes should end with the word “Model” example EmployeeModel, DepartmentModel etc.

The Model class is accessible by both the View and the Controller; the data provided by the Model is used by the view to render information to the user in the browser. The View defines the style and formatting aspects of the display and embeds the data provided by the model to produce a page which has meaningful information.

ASP.NET MVC Architecture

The Asp.Net MVC architecture focuses on separating the UI design and the implementation logic, and thereby improves testability of the application.

The Architecture of Asp.Net MVC makes it possible to make use of advanced client side scripting concepts like JavaScript and jQuery. The Web Forms Architecture also supports JavaScript and jQuery but they don’t mingle well together, the Asp.Net MVC Architecture overcomes this issue and co-ordinates fully with JavaScript, jQuery and other client side scripting frameworks.

MVC stands for

ASP.NET MVC3 Prerequisite

An Asp.Net MVC3 Application need the following minimum requirements.

.NET Framework 4
 ASP.NET 4
 Visual Studio 2010 or Visual Web Developer 2010

Supported Operating Systems:
 

ASP.NET MVC2 Prerequisite


An Asp.Net MVC2 Application need the following minimum requirements.

.Net Framework 3.5
Visual Studio 2008
Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1

Supported Operating Systems: 

Asp.Net MVC Overview

Asp.Net MVC is one of the models provide by Asp.Net to build web applications, this model is based on the MVC (Model View Controller) design pattern. This model focuses in separating the design from the implementation logic, and is aptly applicable where intense testing is required in each of the blocks (design, logic and data access). Since this model separates design and implementation logic, it makes it possible to test each of these blocks individually.

How to find the entity framework version in your Machine

The ADO.Net Entity Framework comes in various versions starting from 3.5, the latest version at the time of writing this post is 6. Each version has its own set of features, so naturally you will need to know the version which you are working with to make use of the features in that version.

To know the version of the Entity Framework in your machine follow the steps below.

ADO.Net Entity Framework call Stored Procedures with Parameters

To work with Model using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity Data Model class, refer to the post Creating your First ADO.Net Entity Data Model to see on how to create an ADO.Net Entity Data Model, that maps to the physical database.

Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model objects. In this post we shall see on how to use the ADO.Net Entity Data Model to call a Stored Procedure and pass parameters to the Procedure.

In this post, we will use an existing Stored procedure and call it using ADO.Net Entity Framework.

ADO.Net Entity Framework call Stored Procedures

In order to select data from a Model using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity Data Model class, refer to the post Creating your First ADO.Net Entity Data Model to see on how to create an ADO.Net Entity Data Model, that maps to the physical database.

Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model objects. In this post we shall see on how to use the ADO.Net Entity Data Model to call a Stored Procedure and bind the results of the procedure to a GridView.

In this post, we will use an existing Stored procedure and call it using ADO.Net Entity Framework.

Tuesday, December 4, 2012

C# Win Form Design

C# Win Form Validation

C# Win Form MDI Form

C# Win Form DataGridView

C# Win Form Controls

C# Win Form App Config

Deleting Data using ADO.Net Entity Framework

In order to select data from a Model using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity Data Model class, refer to the post Creating your First ADO.Net Entity Data Model to see on how to create an ADO.Net Entity Data Model, that maps to the physical database.

Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model to select data. In this post we shall see on how to use the ADO.Net Entity Data Model to DELETE a record in the Employee table.

Updating Data with Foreign Key Reference using ADO.Net Entity Framework

In order to select data from a Model using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity Data Model class, refer to the post Creating your First ADO.Net Entity Data Model to see on how to create an ADO.Net Entity Data Model, that maps to the physical database.

Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model to select data. In this post we shall see on how to use the ADO.Net Entity Data Model to UPDATE a record in the Employee table, which references the Department Table through the Foreign Key DepartmentID 

Updating Data using ADO.Net Entity Framework

In order to select data from a Model using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity Data Model class, refer to the post Creating your First ADO.Net Entity Data Model to see on how to create an ADO.Net Entity Data Model, that maps to the physical database.

Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model to select data. In this post we shall see on how to use the ADO.Net Entity Data Model to UPDATE a record in the Employee table.

Inserting Data with Foreign Key Reference using ADO.Net Entity Framework

In order to select data from a Model using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity Data Model class, refer to the post Creating your First ADO.Net Entity Data Model to see on how to create an ADO.Net Entity Data Model, that maps to the physical database.

Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model to select data. In this post we shall see on how to use the ADO.Net Entity Data Model to INSERT a record into the Employee table, which includes a Foreign Key column DepartmentID.


Inserting Data using ADO.Net Entity Data Model

In order to select data from a Model using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity Data Model class, refer to the post Creating your First ADO.Net Entity Data Model to see on how to create an ADO.Net Entity Data Model, that maps to the physical database.

Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model to select data. In this post we shall see on how to use the ADO.Net Entity Data Model to INSERT a record into the Employee table.


Selecting Data by Joining Tables using ADO.Net Entity Framework


In order to select data from a Model using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity Data Model class, refer to the post Creating your First ADO.Net Entity Data Model to see on how to create an ADO.Net Entity Data Model, that maps to the physical database.

Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model to select data. In this post we shall see on how to use the ADO.Net Entity Data Model to query the data from more than 1 underlying physical database and display the results of the query in a GridView.

Selecting Data using ADO.Net Entity Data Model

In order to select data from a Model using the ADO.Net Entity Data Model, we should first create an ADO.Net Entity Data Model class, refer to the post Creating your First ADO.Net Entity Data Model to see on how to create an ADO.Net Entity Data Model, that maps to the physical database.

Once you have created the ADO.Net Entity Data Model class, we can proceed with querying the model to select data. In this post we shall see on how to use the ADO.Net Entity Data Model to query the data from the underlying physical database and display the results of the query in a GridView.



Creating your First ADO.Net Entity Data Model

First let us create a new ASP.Net Web application project. Note that ADO.Net Entity Data Model Template is not a project type template, it is a file type template, means that you first need to create a project, then add ADO.Net Entity Data Model Template as one of the Items to the project.

Make sure that your Project is mapped to targets Framework 3.5 or Higher, you can check this is the Project Properties, in the Project properties window check that the Target Framework property is set to .net Framework 3.5 or Higher.


ADO.Net Entity Data Model Prerequisite


The following are the minimum pre-requisites to make use of ADO.Net Entity Data Model in your project.

.Net Framework 3.5  SP1

Visual Studio 2008 SP1
Make sure that you have Visual Studio 2008 SP1, ADO.Net Entity Data Model  Templates do        not come with the basic version of Visual Studio 2008, you need to have SP1 installed.

Targets Framework 3.5
Make sure that your Project is mapped to targets framework 3.5, you can check this is the Project Properties, in the Project properties window check that the Target Framework property is set to .net Framework 3.5 or Higher.


Thursday, November 29, 2012

C# Windows Application Update app.config file

In the Post C# Windows Application Reading app.config file, we saw on how to read the key values in the App.config file, there are situations where we will have to update the values in the app.config file dynamically from within the application. 

In this post we shall see on how to update the values in the app.config file from the application.


Adding a Custom Icon to C# Windows Application and Forms

C# Windows applications, by come with the default Application icon, many a times we will want to change the default icon to one which suites the type of application, in this post we shall see on how to change the default icon and set a custom icon.

1. Open the Windows Application project in Visual Studio.
2. Open the Project Properties.
3. In the Applications tab, Under the resources section, browse and select the custom icon file.

Email validation using ErrorProvider in C# Windows Application

C# Windows Application provides an ErrorProvider control, which is similar to the ValidationSummary control in Asp.Net, this control consolidates all the error messages in the form and alerts the user on the Form errors.

In this post we shall see on how to use the ErrorProvider control to validate Email in a C# Windows Form.

RegularExpression Validation using Regex class in C# Windows Application

Asp.Net provides a RegularExpression Validator to validate custom expressions, in Windows Forms there are no such validators. However we can make use of the methods in the Regex class to validate custom expressions in C# Windows forms.

In this post we shall see on how to use the Regex class to validate custom expressions in a C# Windows forms Application.

Wednesday, November 28, 2012

Adding Image Buttons to C# Windows Form

The C# Windows forms buttons are usually rectangular in shaper and take the default Grey color background, however there are instances where we need to make our forms more stylish, in this post we shall see on how to set Images to a Button in a C# Windows forms application.

1. Create a new / open an existing C# Windows application.
2. Create/Open the form which needs the Image Button.
3. Add a button to the Form
4. Set the following Properties to the Button (View -> Properties Window or Press F4 key)

Rounder Corner C# Windows Form

The C# Windows forms are usually rectangular and take the default Grey color background, however there are instances where we need to make our forms more stylish, in this post we shall see on how to set a Rounder Corner appearance to a C# Windows Form.

1. Create a new / open an existing C# Windows application.
2. Create/Open the form which
needs the Rounder Corner appearance.
3. Open the Properties of the form (View -> Properties Window or Press F4 key)
4. Set the
following Properties.

Monday, November 26, 2012

Combobox validation using ErrorProvider in C# Windows Application

C# Windows Application provides an ErrorProvider control, which is similar to the ValidationSummary control in Asp.Net, this control consolidates all the error messages in the form and alerts the user on the Form errors.

In this post we shall see on how to use the ErrorProvider control to validate a ComboBox in a C# Windows Form.

Integer validation using ErrorProvider in C# Windows Application

C# Windows Application provides an ErrorProvider control, which is similar to the ValidationSummary control in Asp.Net, this control consolidates all the error messages in the form and alerts the user on the Form errors.

In this post we shall see on how to use the ErrorProvider control to validate Integers (Whole Numbers) in a C# Windows Form.

Friday, November 23, 2012

Number validation using ErrorProvider in C# Windows Application

C# Windows Application provides an ErrorProvider control, which is similar to the ValidationSummary control in Asp.Net, this control consolidates all the error messages in the form and alerts the user on the Form errors.

In this post we shall see on how to use the ErrorProvider control to validate Numbers in a C# Windows Form.

C# Windows Application Form validation using ErrorProvider


C# Windows Application provides an ErrorProvider control, which is similar to the ValidationSummary control in Asp.Net, this control consolidates all the error messages in the form and alerts the user on the Form errors.

In this post we shall see on the basics of the ErrorProvider control, the successive posts will show on how to use the control to perform various types of validations.

Thursday, November 22, 2012

Binding data to a ListView with Multiple Columns in C# Windows Form

A ListBox control in a C# windows forms, can display only one column of data, but there are instances when we want to display multiple columns of data. One option is to use the DataGrid control, but we can also use the ListView control to display multiple column data.

The
ListView can be used to display static information, which the user will not be changing, in this post we shall see on how to use the ListView control to display multiple columns of data in a C# Windows Form. We shall bind the data from the list view from the code behind file.

C# Windows Forms ListView with multiple columns

A ListBox control in a C# windows forms, can display only one column of data, but there are instances when we want to display multiple columns of data. One option is to use the DataGrid control, but we can also use the ListView control to display multiple column data.

The
ListView can be used to display static information, which the user will not be changing, in this post we shall see on how to use the ListView control to display multiple columns of data in a C# Windows Form.

Tuesday, November 20, 2012

jQuery Mobile Books

jQuery UI Books

jQuery Books

jQuery ajax getScript Method

jQuery ajax getScript Method

jQuery ajax getJSON Method

jQuery ajax getJSON Method

jQuery ajax Post Method

jQuery ajax Get Method

jQuery ajax Load Method

jQuery ajax Method

jQuery Ajax Properties

jQuery Ajax Handlers

jQuery Ajax Overview

jQuery Ajax Overview


Adding TabControl to a C# Windows Form

A TabControl in a C# Windows Form allows us to group controls of different type in different tab panes in the same Form, the user can navigate between various tabs and access the controls in each of the Tabs.

A
TabControl is used when there are multiple controls to be displayed in a single form, TabControls helps in aligning the controls into groups and provides a better UI design to the form, in this post we shall see on how to add TabControls to a C# Windows Form.

Creating MDI Child Forms

MDI (Multiple-Document Interface) applications should have a MDI Parent form which will act as the parent for all other forms in the application. In this post we shall see on how to create a MDI Child form in a C# Windows Application and associate it with the MDI Parent form.

First let us create the MDI Parent Form.

Add Toolbar to a MDI Parent Form

MDI (Multiple-Document Interface) applications should have a MDI Parent form which will act as the parent for all other forms in the application. In this post we shall see on how to add a Toolbar control to an MDI Parent Form.

Monday, November 19, 2012

Add Menu to MDI Parent Form

MDI (Multiple-Document Interface) applications should have a MDI Parent form which will act as the parent for all other forms in the application. In this post we shall see on how to add a Menu control to an MDI Parent Form.

Creating MDI Parent Forms

MDI (Multiple-Document Interface) applications should have a MDI Parent form which will act as the parent for all other forms in the application. In this post we shall see on how to create a MDI Parent form in a C# Windows Application.

1. Create a new / open an existing C# Windows application.
2. Create/Open the form which needs to be set as the MDI Parent form.
3. Open the Properties of the form (View -> Properties Window or Press F4 key)
4. Set the IsMdiContainer property to true.
5. Notice that the Form UI Changes as follows.


MDI Applications (Multiple-Document Interface)

A C# Windows application usually allows only a single Form to be opened at any given point in time, this works fine for smaller applications, but when we need to develop larger applications, we need a comprehensive menu structure to navigate through the various forms, this is where the MDI Applications help us.

Multiple-Document Interface (MDI) application, are those which have a MDI parent form, this form will be the parent of all the other forms in the Application, typically this form will contain the Menu which is used to navigate to the other forms in the application. 

A form in an MDI application is set as the MDI Parent by setting the IsMDIContainer property to true. Once this property is set to true, this form will act as the Parent form for the application. We can add Menu control to this form.

Saturday, November 17, 2012

JQuery Mobile Web Development Essentials (Imported Edition)

Overview
This book helps you to learn
1. Create websites that work beautifully on a wide range of mobile devices with jQuery mobile
2. To prepare your jQuery mobile project by learning through three sample applications
3. Packed with easy to follow examples and clear explanations of how to easily build mobile-optimized websites

Title
JQuery Mobile Web Development Essentials (Imported Edition)
Author
A. Matthews, Raymond Camden
Publisher
Packyt Publishing
Publishing Date
2012
Pages
246
Price
Rs. 2252/-
Price @ Flipkart
Rs. 1847/-