tag:blogger.com,1999:blog-3459441897238693212024-03-05T22:48:29.119-06:00Anupam Dutta(Web and Desktop Application Developer)Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-345944189723869321.post-71128940049091555532013-07-07T02:55:00.000-05:002014-03-04T00:32:44.988-06:00How to restart a server from MSSQL SERVER using xp_cmdshell<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKjOh-n74KKkc46Ahu3iHv1grhE_VFpZ9kYenwjKutM-RDBeU3ROi_qNhcDc2VJEUeX9kr4pqsFDXGglBX9KBjhyefMOp7ZBvGPuSJ4Q6AjwoOlj4ugKQDfVl-xVfePuCY04qqpkDe6RI/s1600/mssql.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKjOh-n74KKkc46Ahu3iHv1grhE_VFpZ9kYenwjKutM-RDBeU3ROi_qNhcDc2VJEUeX9kr4pqsFDXGglBX9KBjhyefMOp7ZBvGPuSJ4Q6AjwoOlj4ugKQDfVl-xVfePuCY04qqpkDe6RI/s200/mssql.png" height="163" width="200" /></a></div>
<div style="text-align: justify;">
Sometimes we need to restart a windows PC or server within or after an interval of time. We can do it easily using 'scheduled task' of windows. Here I‘ll discuss how to do this task from <b><a href="http://mssqlall.blogspot.com/" target="_blank">MS SQL SERVER</a></b>. To do this we'll use a stored procedure ‘xp_cmdshell’ and an ms-dos command ‘shutdown’.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
“xp_cmdshell” is a stored procedure which allows us to execute ms-dos commands from SQL Server.</div>
<div style="text-align: justify;">
<b>Syntax</b></div>
<div style="text-align: justify;">
xp_cmdshell {'command_string'} [, no_output]<br />
<br />
<b>Arguments</b></div>
<div style="text-align: justify;">
<b>command_string:</b> command_string for operating system command (ms-dos command). The maximum length of this parameter is varchar(8000) or nvarchar(4000).</div>
<div style="text-align: justify;">
<b>No_output:</b> No_output Is an optional parameter. After executing the given command_string with No_output it does not return any output to the client.<br />
<br />
<br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
</div>
<br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: 'Times New Roman'; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
<div style="margin: 0px;">
<b><u>Execute following script to enable xp_cmdshell:</u></b></div>
<blockquote class="tr_bq">
<div style="margin: 0px;">
use master</div>
<div style="margin: 0px;">
EXEC sp_configure 'show advanced options', 1</div>
<div style="margin: 0px;">
RECONFIGURE</div>
<div style="margin: 0px;">
EXEC sp_configure 'xp_cmdshell', 1</div>
<div style="margin: 0px;">
RECONFIGURE</div>
</blockquote>
</div>
<br /></div>
<div style="text-align: justify;">
Now we will use ‘shutdown -r -f -t 01’ as a command_string. </div>
<div style="text-align: justify;">
Here, </div>
<div style="text-align: justify;">
Shutdown is a dos-command which is used to shut down, restart, log off or hibernate a computer.</div>
<div style="text-align: justify;">
-r for restart, -f Forces running applications to close without warning, -t 01 for restart within 1 second.</div>
<div style="text-align: justify;">
Finally we will execute following sql procedure.</div>
<div style="text-align: justify;">
EXEC master..xp_cmdshell 'shutdown -r -f -t 01'</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
If it is required to restart a PC/server every day then we can use <b><a href="http://duttanup.blogspot.com/2013/04/ms-sql-server-job.html" target="_blank">MS SQL SERVER JOB</a>.</b></div>
</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com0tag:blogger.com,1999:blog-345944189723869321.post-44325887864992798282013-07-03T11:45:00.000-05:002014-01-23T00:23:17.613-06:00Some new structural tags in HTML5<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Before <b>HTML5</b>, <div> elements were the only opportunity for defining block-level page structure. <b>HTML5</b> introduced us with few important structural elements: <b>header</b>, <b>footer</b>, <b>nav</b>, <b>article</b>, <b>section</b>, <b>aside</b> and <b>hgroup</b>. The new elements simply give us an element that carries more meaning, with which to replace the generic <div>.<br />
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5l-u7a42d4ioojAi550dlOSBjh2HVZMJ-V9cSCWxKNzbBRJ0kB9EmUVq9JIJTee91PfT3ZxhnTccLrvmW-Zqc-xmSV-7_C3sVRIPMvRklXsyxDahIUt2TqGmaM9eKubxrb6tEHBMvk-g/s676/Structural+Tag.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="structural tags in html5" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5l-u7a42d4ioojAi550dlOSBjh2HVZMJ-V9cSCWxKNzbBRJ0kB9EmUVq9JIJTee91PfT3ZxhnTccLrvmW-Zqc-xmSV-7_C3sVRIPMvRklXsyxDahIUt2TqGmaM9eKubxrb6tEHBMvk-g/s400/Structural+Tag.jpg" height="315" title="" width="400" /></a></div>
<br />
<div style="text-align: justify;">
<b>Header</b>: Header element is designed for the header area of a page or page section. The header element can contain h1-h6 heading tag and other elements as well. it can be nested within each <article> element of a single web page.</div>
<blockquote class="tr_bq">
<header><br />
<h1>Anupam Dutta</h1><br />
<h2>(Web and Desktop Application Developer)</h2><br />
</header></blockquote>
<div style="text-align: justify;">
<b>Footer</b>: The footer tag of HTML5 usually contains information of a section or document. Basically author information, copyright data, links to related documents, social networking and sharing links are placed within the footer tag.</div>
<blockquote class="tr_bq">
<footer><br />
<h3> Copyright 2013 Anupam Dutta</h3><br />
</footer></blockquote>
<div style="text-align: justify;">
<b>Nav</b>: Nav element contains the navigation functionality of a page such as table of contents and menu. Nav can appear more than once in a web page.</div>
<blockquote class="tr_bq">
<nav><br />
<ul><br />
<li><a href="#HOME">HOME</a></li><br />
<li><a href="#MVC">MVC</a></li> <br />
<li><a href="#MSSQL">MSSQL</a></li> <br />
<li><a href="#HTML5">HTML5</a></li> <br />
<li><a href="#ABOUT">ABOUT</a></li> <br />
</ul><br />
</nav></blockquote>
<div style="text-align: justify;">
<b>Section</b>: The section element is similar to <div> as a general container which represents a standard section of a document, web page or application, such as a chapter, for example. It has some semantic meaning. Section is a sectional element but <div> is not a sectional element. Section indicates a new section in a document.</div>
<blockquote class="tr_bq">
<section id="MSSQL"><br />
<h2> MSSQL DATABASE BACKUP</h2><br />
<!-- multiple article elements could go in here --><br />
</section></blockquote>
<blockquote class="tr_bq">
<section id="MVC"><br />
<h2> ASP.NET MVC SCAFFOLDING IN CODE FIRST SCENARIOS </h2><br />
<!-- multiple article elements could go in here --><br />
</section></blockquote>
<div style="text-align: justify;">
<b>Article</b>: The article element represents an independent section of a document, page or site. It is appropriate for content like a magazine or newspaper article, blog articles, individual comments or forum posts, an interactive gadget or widget.</div>
<blockquote class="tr_bq">
<article><br />
<section id="MVC"><br />
<h2>ASP.NET MVC SCAFFOLDING IN CODE FIRST SCENARIOS</h2><br />
</section><br />
<section id="MSSQL"><br />
<h2>MSSQL DATABASE BACKUP</h2><br />
</section><br />
</article></blockquote>
<div style="text-align: justify;">
<b>Aside</b>: The aside element is for content that is tangentially related to another content item (such as a section or article), and is typically useful for marking up sidebars.</div>
<blockquote class="tr_bq">
<aside><br />
<table><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><h2>Related post</h2><br />
<!-- lots of quick facts inside here --><br />
</table><br />
</aside></blockquote>
<div style="text-align: justify;">
<b>Hgroup</b>: The hgroup element is used to group any set of h1 - h6 elements when the heading has multiple levels.</div>
<blockquote class="tr_bq">
<header><br />
<hgroup><br />
<h1>Anupam Dutta</h1><br />
<h2>(Web and Desktop Application Developer)</h2><br />
</hgroup><br />
</header></blockquote>
<div>
<br /></div>
</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com0tag:blogger.com,1999:blog-345944189723869321.post-57087220284827572012013-06-27T03:43:00.005-05:002013-06-27T03:44:46.727-05:00Audio and Video in HTML5<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<<b>audio</b>> and <<b>video</b>> tags of <b>HTML5</b> allows us to incorporate native audio and video support without Flash.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
To include <b>audio</b> and <b>video</b> we need to set src attribute to identify the media source and include a controls attribute so the user can play and pause the media.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The simplest way of embedding a video file in a webpage:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<video src="video.mp4" width="320" height="200" controls preload></video></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<audio src="audio.mp3" controls preload></audio></div>
<br />
<span style="text-align: justify;">We can use <source> tag to indicate media along with media type and many other attributes. A video/Audio element allows various source elements and browser will use the first recognized format:</span><br />
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<video width="618" height="347" controls preload> </div>
<div style="text-align: justify;">
<source src="video.mp4" media="only screen and (min-device-width: 568px)"></source></div>
<div style="text-align: justify;">
<source src="video.iphone.mp4" media="only screen and (max-device-width: 568px)"></source></div>
<div style="text-align: justify;">
</video></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<audio controls preload> </div>
<div style="text-align: justify;">
<source src="audio.mp3"></source> </div>
<div style="text-align: justify;">
<source src="audio.ogg"></source> </div>
<div style="text-align: justify;">
</audio></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b><u>Attribute Specification:</u></b></div>
<div style="text-align: justify;">
<b>Autoplay:</b> The video/audio will automatically begin to play back as soon as it can do so without stopping to finish loading the data.</div>
<div style="text-align: justify;">
<b>Autobuffer:</b> The video/audio will automatically begin buffering even if it's not set to automatically play.</div>
<div style="text-align: justify;">
<b>Controls:</b> It will allow the user to control video/audio playback, including volume, seeking, and pause/resume playback.</div>
<div style="text-align: justify;">
<b>Loop:</b> It will allow video/audio automatically seek back to the start after reaching at the end.</div>
<div style="text-align: justify;">
<b>Preload:</b> This attribute specifies that the video/audio will be loaded at page load, and ready to run. Ignored if autoplay is present.</div>
<div style="text-align: justify;">
<b>Src:</b> The URL of the video/audio to embed.</div>
<div style="text-align: justify;">
<b>Height:</b> Height of the video's display area in pixels.</div>
<div style="text-align: justify;">
<b>Width:</b> Width of the video's display area in pixels.</div>
<div style="text-align: justify;">
<b>Poster:</b> URL of an image which will be displayed while the video is loading.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com1tag:blogger.com,1999:blog-345944189723869321.post-91317791479475599472013-06-15T01:47:00.004-05:002014-01-23T00:26:50.312-06:00MSSQL Database Backup<div dir="ltr" style="text-align: left;" trbidi="on">
Database backup is a very important thing if you don’t want to drop any of your valuable data that you are storing. Here, I’ll explain how to create <a href="http://mssqlall.blogspot.com/" target="_blank">MSSQL</a> database backup.<br />
<br />
Step-1:<br />
Create a stored procedure from following script.<br />
<blockquote class="tr_bq">
CREATE procedure prcDBBackup<br />
as<br />
<br />
declare @dbname varchar(100)<br />
select @dbname = CONVERT(VARCHAR(10),GETDATE(),101)+CONVERT(VARCHAR(8),GETDATE(),108)<br />
select @dbname = replace(replace(@dbname,'/',''),':','')<br />
set @dbname = (select'E:\ERP_DB_BACKUP\ERP_DB_' + @dbname + '.BAK')<br />
BACKUP DATABASE ERP<br />
TO DISK = @dbname</blockquote>
Replace 'E:\ERP_DB_BACKUP\ERP_DB’ with your destination path.<br />
<br />
Step-2:<br />
Execute following sql command to create a backup manually.<br />
<blockquote class="tr_bq">
exec prcDBBackup </blockquote>
To create an automatic daily backup you can create a <a href="http://duttanup.blogspot.com/2013/04/ms-sql-server-job.html" target="_blank">MS SQL SERVER JOB</a>.</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com0tag:blogger.com,1999:blog-345944189723869321.post-78490258725315121492013-05-23T22:08:00.001-05:002015-03-03T03:38:14.448-06:00How to access an Existing Database Using Entity Framework 5.0 Code-First<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="text-align: justify;">In my previous two articles we see how to use </span><a href="http://duttanup.blogspot.com/2013/04/create-application-using-aspnet-mvc-4.html" style="text-align: justify;" target="_blank">Entity Framework Code First</a><span style="text-align: justify;"> and </span><a href="http://duttanup.blogspot.com/2013/04/aspnet-mvc-scaffolding-in-code-first.html" style="text-align: justify;" target="_blank">mvcscaffolding</a><span style="text-align: justify;"> in <a href="http://amzn.to/1wGpCWy" target="_blank">asp.net mvc4</a>. We didn't create any database into above articles. Database was created automatically from model class. But in this article I’ll explain how to use existing database in an EF code-first application. For this purpose we’ll make two small changes in any asp.net mvc code-first project.</span><br />
<br />
<div style="text-align: justify;">
1. Define connectionstring in web.config for existing database.</div>
<div style="text-align: justify;">
<br /></div>
<connectionStrings><br />
<add name="DonarConnectionString" connectionString="Data Source=MSSQLSERVER;initial catalog=BloodDonar;user id=sa;password=;Integrated Security=SSPI;" providerName="System.Data.SqlClient" /><br />
</connectionStrings><br />
<br />
<div style="text-align: justify;">
2. In previous two articles we have created a database context class which is inherited from “DbContext”. Now we need a constructor for this class. Notice, in this constructor, that we call into the base constructor and pass it a string. This is the connectionstring which is created in previous step. EF will use it during database connections.</div>
<br />
public InventoryContext(): base("name=DonarConnectionString")<br />
{<br />
Database.SetInitializer<MvcApplication2Context>(null);<br />
}<br />
<br />
<div style="text-align: justify;">
Here, we are setting the Initializer for the context to null with SetInitializer<>. So, EF will not try to change any database initialization logic.</div>
</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com0tag:blogger.com,1999:blog-345944189723869321.post-64245356965492974982013-04-29T12:58:00.004-05:002015-03-03T04:51:50.137-06:00Asp.net MVC Scaffolding in code first scenarios<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="text-align: justify;">
In this article we will walk through the creation of a read/write/update/delete of Recipes and its related (many) Ingredients using MvcScaffolding and <a href="http://amzn.to/1wGpCWy" target="_blank">MVC</a> 4.</div>
<br />
<div style="text-align: justify;">
MVC Scaffolding gives you a fast way to get some helpful, effective code, that you can then edit and adapt according to your needs.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
In other words, MvcScaffolding can create automatically:</div>
<div style="text-align: justify;">
1. Controllers for creating, viewing, updating and deleting instances of your model,</div>
<div style="text-align: justify;">
2. Corresponding Views for creating, viewing, updating, and deleting data,</div>
<div style="text-align: justify;">
3. Database contexts from your model,</div>
<div style="text-align: justify;">
4. Catalyze the creation of a database model including support for one-to-many relationships and more…</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
In this article we'll create a blood donar application using MVC Scaffolding and code first.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Let’s create two models for blood group and donar. Add the following classes to our Models folder, then compile the solution :</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
BloodGroup.cs</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
using System.Collections.Generic;</div>
<div style="text-align: justify;">
using System.Linq;</div>
<div style="text-align: justify;">
using System.Text;</div>
<div style="text-align: justify;">
using System.ComponentModel;</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
namespace Blood_Donar.Models</div>
<div style="text-align: justify;">
{</div>
<div style="text-align: justify;">
public class bloodgroup</div>
<div style="text-align: justify;">
{</div>
<div style="text-align: justify;">
public int bloodgroupid { get; set; }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
[DisplayName ("Blood Group")]</div>
<div style="text-align: justify;">
public string name { get; set; }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Donar.cs</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
using System;</div>
<div style="text-align: justify;">
using System.Collections.Generic;</div>
<div style="text-align: justify;">
using System.Linq;</div>
<div style="text-align: justify;">
using System.Web;</div>
<div style="text-align: justify;">
using System.ComponentModel;</div>
<div style="text-align: justify;">
using System.ComponentModel.DataAnnotations;</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
namespace Blood_Donar.Models</div>
<div style="text-align: justify;">
{</div>
<div style="text-align: justify;">
public class donar</div>
<div style="text-align: justify;">
{</div>
<div style="text-align: justify;">
public int ID { get; set; }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
[DisplayName ("Donar Name")]</div>
<div style="text-align: justify;">
[Required(ErrorMessage="Name is required")]</div>
<div style="text-align: justify;">
public string Name { get; set; }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
public string Address { get; set; }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
[Required(ErrorMessage="Mobile no is required.")]</div>
<div style="text-align: justify;">
public int Mobile { get; set; }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
[DisplayName ("Blood Group")]</div>
<div style="text-align: justify;">
public int bloodgroupid { get; set; }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
public virtual bloodgroup bloodgroups { get; set; }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Execute following command into Package Manager Console:</div>
<div style="text-align: justify;">
1. Install-Package EntityFramework</div>
<div style="text-align: justify;">
2. Install-Package mvcscaffolding</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Next, we will create a complete Create-Read-Update-Delete (CRUD) UI for those models by executing a single command into Package Manager Console:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Scaffold Controller Donar</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
This command will create a database context, a controller, and all the views for Create-Read-Update-Delete (CRUD) actions. Right now you can run it (Shift-F5).</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
If you have SQL Server Express running on your machine, EFCodeFirst will automatically connect to it, create your database schema, and you’ve got a basic working application without writing a single line of procedural code. Also you can add a SQL Server Compact to your project by issuing the following command in the Package Manager Console:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Install-Package EFCodeFirst.SqlServerCompact</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Again, execute following command for BloodGroup model</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Scaffold Controller BloodGroup</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
To create repositary class execute following command into package manager console</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Scaffold Controller Donar –Repository -Force</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Now the scaffolder will produce two additional class, Donar Repository, and the following interface which Donar Repository implements:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
public interface IdonarRepository</div>
<div style="text-align: justify;">
{</div>
<div style="text-align: justify;">
IQueryable<donar> All { get; }</div>
<div style="text-align: justify;">
IQueryable<donar> AllIncluding(params Expression<Func<donar, object>>[] includeProperties);</div>
<div style="text-align: justify;">
donar Find(int id);</div>
<div style="text-align: justify;">
void InsertOrUpdate(donar donar);</div>
<div style="text-align: justify;">
void Delete(int id);</div>
<div style="text-align: justify;">
void Save();</div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Follow same process for Bloodgroup.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Now run the application and see the magic of MVCScaffolding.</div>
<div style="text-align: justify;">
<br /></div>
</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com0tag:blogger.com,1999:blog-345944189723869321.post-78871308239596099692013-04-24T23:01:00.000-05:002015-03-03T04:52:25.537-06:00Create an application using asp.net MVC 4 and EF code first<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
In this tutorial we will create our first <a href="http://amzn.to/1wGpCWy" target="_blank">MVC</a> application using visual studio 2012, MVC 4 and EntityFramework Code First.</div>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Step-1: Create Project</div>
<div style="text-align: justify;">
1. In Visual Studio 2012, add a new project by selecting the File menu, then New and then Project.</div>
<div style="text-align: justify;">
2. Select ASP.NET MVC 4 Web Application and C# as a language of choice.</div>
<div style="text-align: justify;">
3. Name the project Inventory and then click OK.</div>
<div style="text-align: justify;">
4. In the New ASP.NET MVC 4 Project wizard, choose Internet Application and razor view engine.</div>
<div style="text-align: justify;">
5. Leave the default values of the other options and click OK.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Step-2: Create a model class</div>
<div style="text-align: justify;">
1. In Solution Explorer, right click the Models folder.</div>
<div style="text-align: justify;">
2. Select Add from the menu and then from the bottom of its context menu choose Class.</div>
<div style="text-align: justify;">
3. In the Add New Item dialog, change the new class name to Category.</div>
<div style="text-align: justify;">
4. A new file, Category will be created.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Add following code into category class.</div>
<div style="text-align: justify;">
using System;</div>
<div style="text-align: justify;">
using System.Collections.Generic;</div>
<div style="text-align: justify;">
using System.Linq;</div>
<div style="text-align: justify;">
using System.Web;</div>
<div style="text-align: justify;">
using System.ComponentModel;</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
namespace Inventory.Models</div>
<div style="text-align: justify;">
{</div>
<div style="text-align: justify;">
public class Category</div>
<div style="text-align: justify;">
{</div>
<div style="text-align: justify;">
public int CategoryID { get; set; }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
[DisplayName("Category Name")]</div>
<div style="text-align: justify;">
public string CategoryName { get; set; }</div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Now, We’ll create a class that inherits from DbContext and knows how to serve up and manage the Category object. The Entity Framework will take care of bridging the classe and a database. Before the use of DbContext, we’ll need to create a reference to the Entity Framework API. This is the assembly that contains the Code First runtime. Visual studio 2012 automatically creates a reference of Entity Frmework. But for VS 2008 or 2010 we need to create a reference of EF by using Nuget. Nuget allows us to easily find and install reference assemblies from the internet.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
1. Select the Inventory project in Solution Explorer.</div>
<div style="text-align: justify;">
2. From the Tools Menu, choose Library Package Manager which has a sub-menu.</div>
<div style="text-align: justify;">
3. From the sub-menu choose Package Manager Console.</div>
<div style="text-align: justify;">
4. At the console’s PM prompt type install-package EntityFramework then hit enter.</div>
<div style="text-align: justify;">
When the package is installed, you should see the “success message”.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Add following class to the Models folder and compile the application.</div>
<div style="text-align: justify;">
using System;</div>
<div style="text-align: justify;">
using System.Collections.Generic;</div>
<div style="text-align: justify;">
using System.Linq;</div>
<div style="text-align: justify;">
using System.Web;</div>
<div style="text-align: justify;">
using System.Data.Entity;</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
namespace Inventory.Models</div>
<div style="text-align: justify;">
{</div>
<div style="text-align: justify;">
public class InventoryContext: DbContext</div>
<div style="text-align: justify;">
{</div>
<div style="text-align: justify;">
public DbSet<Category> Categories { get; set; }</div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
}</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Step-3: Create Controller</div>
<div style="text-align: justify;">
1. Build the project by choosing Build from the Visual Studio menu and then Build Inventory from its drop-down menu.</div>
<div style="text-align: justify;">
2. In the Solution Explorer, right click the Controllers folder.</div>
<div style="text-align: justify;">
3. Click Add from its context menu and then Controller.</div>
<div style="text-align: justify;">
4. In the Add Controller window, change the Controller Name to CategoryController and select MVC Controller with read/write and view using EntityFramework.</div>
<div style="text-align: justify;">
5. Select Model Class: Category(Inventory.Models).</div>
<div style="text-align: justify;">
6. Select DBContext Class: InventoryContext.Models).</div>
<div style="text-align: justify;">
7. Views: Razor(cshtml).</div>
<div style="text-align: justify;">
Click the Add button.</div>
<div style="text-align: justify;">
The CategoryController class will be created with ActionResult methods: Index, Details, Create, Edit and Delete.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Step-4: Change the global.asax</div>
<div style="text-align: justify;">
1. Open the global.asax file from Solution Explorer.</div>
<div style="text-align: justify;">
2. Modify the MapRoute call to change the value of controller from “Home” to “Category”.</div>
<div style="text-align: justify;">
routes.MapRoute(</div>
<div style="text-align: justify;">
"Default", // Route name</div>
<div style="text-align: justify;">
"{controller}/{action}/{id}", // URL with parameters</div>
<div style="text-align: justify;">
new { controller = "Category", action = "Index", id = UrlParameter.Optional }</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Our first application is created. Run the application. The CategoryController.Index action will be the first method called.</div>
<div>
<div style="text-align: justify;">
<br />
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ac&ref=qf_br_asin_til&ad_type=product_link&tracking_id=wwwtechnoearn-20&marketplace=amazon&region=US&placement=1118794753&asins=1118794753&linkId=AXRE5BOLTIWSM3XD&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;">
</iframe>
</div>
</div>
</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com0tag:blogger.com,1999:blog-345944189723869321.post-4205242373649719742013-04-22T12:03:00.000-05:002014-01-23T00:27:25.951-06:00MS SQL Server Job<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
A <a href="http://mssqlall.blogspot.com/" target="_blank">SQL</a> Job is a collection of steps executed by the database engine by SQL ServerAgent.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The job can perform many different functions within it that can save time and effort on the part of employees.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Let us consider a procedure PrcDailyUpdateForecast which will be executing hourly.</div>
<div style="text-align: justify;">
</div>
<br />
<div style="text-align: justify;">
Minimally, it takes two or three steps to set up a scheduled task to execute the code of your choice. First, go to the Management node, SQL Server Agent, and highlight jobs. Right-click, new job, and give it a name like UpdateForecast. Move to the steps tab, add a step called S1.</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSmGUnxX9Wqf6CGmkbB1soqAH4oTuzJY3M1Te6Vg62b6ZLClXoLIK4NhsFU3LIVwBSrjLNQiQgfyHnvgTFKzftXGvY9TWqYd5LbLCiAJPdY6ohAZOhUTtdKUoo_D_OaSj35IAvrp-h6_c/s1600/1.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSmGUnxX9Wqf6CGmkbB1soqAH4oTuzJY3M1Te6Vg62b6ZLClXoLIK4NhsFU3LIVwBSrjLNQiQgfyHnvgTFKzftXGvY9TWqYd5LbLCiAJPdY6ohAZOhUTtdKUoo_D_OaSj35IAvrp-h6_c/s400/1.gif" height="197" width="400" /></a></div>
<div style="text-align: justify;">
<span id="goog_35920011"></span><span id="goog_35920012"></span><br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The first tab (General) of this dialog shows the name of the job, when the job was created, whether or not the job is enabled, the category the job falls into, who owns the job within the database and a description of the job.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
To disable a SQL Server job, uncheck the Enabled checkbox and the job will no longer run in the database if it was scheduled to do so.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The Steps tab of this dialog brings up the following screen:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Each step within the job will be identified within this screen.</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaGH2_6_kJbCHYeOAVRcmelUVGAB3kzOA9yhhTUIshdD7PVpeb91C-PweZZIZSxT9ceLcj8h6c5YSozgKOYqmhXuuyItKJmMTXvnjTufOO5Rt5UErEYA5bipBxQ0y7vDagzWJWP7nqJwY/s1600/2a.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaGH2_6_kJbCHYeOAVRcmelUVGAB3kzOA9yhhTUIshdD7PVpeb91C-PweZZIZSxT9ceLcj8h6c5YSozgKOYqmhXuuyItKJmMTXvnjTufOO5Rt5UErEYA5bipBxQ0y7vDagzWJWP7nqJwY/s400/2a.gif" height="197" width="400" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
These steps can include executing data transformation packages, executing queries, executing stored procedures, etc.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Within this interface you can move the order of the steps around so that they occur in a specific order, as well as, add new steps or edit existing steps.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
If you select a step and select the Edit button, the following screen appears:</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggtz4865cwTSPqiB3IQUQlK70VOONUBmoujAP0PqMqImp4YmFb0DpA_tI3cGILSZ5T6VvY2c1pEXOnxJ2bL3JijatyXQdW0nwQn7mVMaP9fqkLgamr0xcODHD7TaiSV0s7gv0ACQcntn4/s1600/2b.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggtz4865cwTSPqiB3IQUQlK70VOONUBmoujAP0PqMqImp4YmFb0DpA_tI3cGILSZ5T6VvY2c1pEXOnxJ2bL3JijatyXQdW0nwQn7mVMaP9fqkLgamr0xcODHD7TaiSV0s7gv0ACQcntn4/s400/2b.gif" height="272" width="400" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
This screen is used to set the command that is to be executed during the current step.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
You can also specify the name of the step, the type of command to execute and the exit code of the process if successful.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The tab also has a Schedule tab that can be used to manage the schedule of theSQL Server jobs.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
This will allow the job to be set to occur once a daily, multiple times per day, weekly, monthly or just a one time. The job can be set to run at a certain times per day on a recurring basis as well, such as every hour or at a certain time per day.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The following screen shows the scheduling tab:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
To work with the schedule, click the New Schedule or the Edit button.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The New Schedule button will allow a new schedule to be input for the job.</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxwZFoDMCf495zYZbWtdPOJFuJ5NA3exSCpdSNtPEGXudwq022g5mzPbpWHT_haKGEms_xgSs3JsDmkUzPIuHXYAF_smFhB5MCIgVLkdQjJKqnR_TJ_SPajNetSmdx8tUWiuCuQjb-62Q/s1600/3a.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxwZFoDMCf495zYZbWtdPOJFuJ5NA3exSCpdSNtPEGXudwq022g5mzPbpWHT_haKGEms_xgSs3JsDmkUzPIuHXYAF_smFhB5MCIgVLkdQjJKqnR_TJ_SPajNetSmdx8tUWiuCuQjb-62Q/s400/3a.gif" height="198" width="400" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The Edit button will allow the edit of the current schedule.</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPfU9cY96xBEmiDq_zc5V-o0zLdiGvoyT28BbsjncR-zT1vhmHv2-1eVtnXGq_ktX5PV3lCPZMaVL8epIBsueb_eGkQY57aKYeGDaKMeuVI8QKJqpRLVZqQC10gjvbGzZoFiRnNLXb01s/s1600/3b.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPfU9cY96xBEmiDq_zc5V-o0zLdiGvoyT28BbsjncR-zT1vhmHv2-1eVtnXGq_ktX5PV3lCPZMaVL8epIBsueb_eGkQY57aKYeGDaKMeuVI8QKJqpRLVZqQC10gjvbGzZoFiRnNLXb01s/s400/3b.gif" height="220" width="400" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9hraKOhtJcBeuyxzUqqhl8yJ75htcrZhRVtvBm5Dx-Ro9NamKl7TV3s7ftMHY3w-ag_nriV7I-YNcfFhT-EZD35ImVnR-gYwGdkx5Pa1bP5E8q01BNYACQ1mS5Fm_9AEO3mJsXvorZQU/s1600/3c.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9hraKOhtJcBeuyxzUqqhl8yJ75htcrZhRVtvBm5Dx-Ro9NamKl7TV3s7ftMHY3w-ag_nriV7I-YNcfFhT-EZD35ImVnR-gYwGdkx5Pa1bP5E8q01BNYACQ1mS5Fm_9AEO3mJsXvorZQU/s400/3c.gif" height="290" width="400" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
There is also a Notifications tab that can be used to handle notifications from theSQL Server in the event that something unusual occurs with the job while it is running.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The following screen shows the notification dialog which allows the selection of notifications options:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Notifications can be sent in multiple methods. For the notification to work, there must be operators set up within SQL Server to receive them.</div>
<div style="text-align: justify;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu4dzpKrF7lLl2LLTfBghd6RGsYTqIU_zeDK3orcziKdAnyLNFmFO20a2ucz-fyycm-gYMvChLwABfHGcCJEWkKChJbaV3v8qABAGSmki74ypy0XnPbbENTH2RiLL0btCX999axyFIQ28/s1600/4.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu4dzpKrF7lLl2LLTfBghd6RGsYTqIU_zeDK3orcziKdAnyLNFmFO20a2ucz-fyycm-gYMvChLwABfHGcCJEWkKChJbaV3v8qABAGSmki74ypy0XnPbbENTH2RiLL0btCX999axyFIQ28/s400/4.gif" height="198" width="400" /></a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The notification can be an email, a page or a net send. Each notification can be used to alert the operator that something has occurred on the server and the actions are controlled by SQL Server Agent.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Once the SQL Server job is configured, the changes can be saved and the job can now be used to perform routine tasks on a regular basis which can free up resources within your organization.</div>
<div style="text-align: justify;">
<br /></div>
</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com0tag:blogger.com,1999:blog-345944189723869321.post-31694998221056651652013-04-20T03:45:00.002-05:002014-01-23T00:28:07.291-06:00SQL Cursor<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_CkXQSWS0rVvy9M3JyKpzVTFoXMWM3Wx_S-chzIrV5JFGCqwldt28SGBA7XGY_ZQlML9CQt6PMogH1ZjlXPgaAcXmsoPtnE9EkddOdFSb-KLt21AL81hTfqTc02kI79cjvX6RE-InWFs/s1600/mssql.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_CkXQSWS0rVvy9M3JyKpzVTFoXMWM3Wx_S-chzIrV5JFGCqwldt28SGBA7XGY_ZQlML9CQt6PMogH1ZjlXPgaAcXmsoPtnE9EkddOdFSb-KLt21AL81hTfqTc02kI79cjvX6RE-InWFs/s320/mssql.png" height="263" width="320" /></a></div>
<a href="http://mssqlall.blogspot.com/" target="_blank">SQL Server</a> is very good at handling sets of data. For example, you can use a single UPDATE statement to update many rows of data. There are times when you want to loop through a series of rows a perform processing for each row. In this case you can use a cursor.</div>
<br />
<br />
<div style="text-align: justify;">
The basic syntax of a cursor is:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Declare @vStyleID varchar(50)</div>
<div style="text-align: justify;">
Declare @Qty numeric</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
set @Qty = 0</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
DECLARE CurClosing CURSOR FOR</div>
<div style="text-align: justify;">
select DISTINCT vStyleID from tmprptstylewiseclosingreport</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
OPEN CurClosing</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
FETCH NEXT FROM CurClosing</div>
<div style="text-align: justify;">
INTO @vStyleID</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
WHILE @@FETCH_STATUS = 0</div>
<div style="text-align: justify;">
BEGIN</div>
<div style="text-align: justify;">
set @Qty = (select sum(iTotalQty) from vwAutogenID where vStyleID = @vStyleID)</div>
<div style="text-align: justify;">
update tmprptstylewiseclosingreport</div>
<div style="text-align: justify;">
set nOrderQty = @Qty</div>
<div style="text-align: justify;">
where vStyleID = @vStyleID</div>
<div style="text-align: justify;">
set @Qty = 0</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
FETCH NEXT FROM CurClosing</div>
<div style="text-align: justify;">
INTO @vStyleID</div>
<div style="text-align: justify;">
end</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
CLOSE CurClosing</div>
<div style="text-align: justify;">
DEALLOCATE CurClosing</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Based on the example above, cursors include these components:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
• DECLARE statements – Declare variables used in the code block</div>
<div style="text-align: justify;">
• SET\SELECT statements – Initialize the variables to a specific value</div>
<div style="text-align: justify;">
• DECLARE CURSOR statement – Populate the cursor with values that will be evaluated</div>
<div style="text-align: justify;">
NOTE – There are an equal number of variables in the DECLARE CURSOR FOR statement as there are in the SELECT statement. This could be 1 or many variables and associated columns.</div>
<div style="text-align: justify;">
• OPEN statement – Open the cursor to begin data processing</div>
<div style="text-align: justify;">
• FETCH NEXT statements – Assign the specific values from the cursor to the variables</div>
<div style="text-align: justify;">
NOTE – This logic is used for the initial population before the WHILE statement and then again during each loop in the process as a portion of the WHILE statement</div>
<div style="text-align: justify;">
• WHILE statement – Condition to begin and continue data processing</div>
<div style="text-align: justify;">
• BEGIN…END statement – Start and end of the code block</div>
<div style="text-align: justify;">
NOTE – Based on the data processing multiple BEGIN…END statements can be used</div>
<div style="text-align: justify;">
• Data processing – In this example, this logic is to backup a database to a specific path and file name, but this could be just about any DML or administrative logic</div>
<div style="text-align: justify;">
• CLOSE statement – Releases the current data and associated locks, but permits the cursor to be re-opened</div>
<div style="text-align: justify;">
• DEALLOCATE statement – Destroys the cursor</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com0tag:blogger.com,1999:blog-345944189723869321.post-8191404094614428362013-04-17T11:33:00.001-05:002015-03-03T04:52:58.804-06:00Introduction to MVC Concepts<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="text-align: justify;">
The intension of <a href="http://amzn.to/1wGpCWy" target="_blank">MVC</a> or Model-View-Controller is to build applications in a modular way. In MVC, 3 general parts/layers are responsible for creating the output and allowing the interaction with the user:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
1.Model</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
2.View</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
3.Controller</div>
<br />
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Model:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
In the context of the MVC the model has the data that is essential to render things in the view. So it represents the data that are mandatory for rendering. It also takes over the process related to the domain. The model is used to do something and get the data.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
View:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
A view takes care of “rendering the pixels on the screen“and should be as dump as possible. Naturally a view class understands one or more model(s) and outputs the information of that model. (A view is not allowed to write in the model.) So the view is conscious of the model and knows how to read the data out of it – but never the model should know something about the view!</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Controller:</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
It glues together Model and View, it controls the user communication with the model and the view. (It’s a thin layer that connects models with their views)</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The diagram below illustrates a common request cycle in an MVC application.</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_gA0k9cc4nSKNuH1UPJLbQdeT4c7vhbnFd8pmer9y8FY1qPf4Uqc6w89PoNESXn0ywIQY0A15-kF8d11BwMHGOJMiO14c5I3GkAIldxK0vkUxiS7hQbtZ47IIlGR58_0lX272sbH6HUg/s1600/mvc-request-cycle.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_gA0k9cc4nSKNuH1UPJLbQdeT4c7vhbnFd8pmer9y8FY1qPf4Uqc6w89PoNESXn0ywIQY0A15-kF8d11BwMHGOJMiO14c5I3GkAIldxK0vkUxiS7hQbtZ47IIlGR58_0lX272sbH6HUg/s1600/mvc-request-cycle.JPG" /></a></div>
<br />
<div style="text-align: justify;">
The process begins when a user takes an action on a web page – submitting a form that adds a new blog post, for example. The request is sent to the blog controller, which extracts the data submitted via the HTTP POST request and sends a message to the blog model to save a new post with this data.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The model checks the data against its validation rules. Assuming it passes validation; the model stores the data for this new post in the database and tells the controller it was successful. The controller then sets a variable for the view indicating success.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Finally, the view displays this message to the user back on the web page, and they know their new blog post has been successfully created. If, for some reason, validation of the data failed, the model would alert the controller of any errors, which would set a variable containing these errors for the view. The view would then present the original form along with the error messages for any fields that didn’t validate.</div>
<div style="text-align: justify;">
<br /></div>
<br />
<div class="post-body entry-content" id="post-body-7361997312255632664" itemprop="articleBody" style="background-color: white; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; position: relative;">
<div style="clear: both;">
</div>
</div>
<div class="post-footer" style="background-color: white; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 1.6; margin: 1.5em 0px 0px;">
</div>
</div>
Anupam Duttahttp://www.blogger.com/profile/11780352985088613152noreply@blogger.com0