Sunday, November 27, 2011

FILESTREAM in Sql Server 2008 and Example

FILESTREAM in SQL Server 2008

SQL Server 2008 introduces the new FILESTREAM attribute, which can be applied to the varbinary(max) data type. Using FILESTREAM, you can exceed the 2GB limit on stored values and take advantage of relational handling of files via SQL Server, while actually storing the files on the file system. BACKUP and RESTORE operations maintain both the database data as well as the files saved on the file system, thus handling end-to-end data recoverability for applications that store both structured and unstructured data. FILESTREAM marries the transactional consistency capabilities of SQL Server with the performance advantages of NT file system streaming.

SQL Server can manage the contents of the FILESTREAM containers on the file system for you and control access to the files, while the NT File System (NTFS) provides efficient file streaming and file system transaction support. This combination of SQL Server and NTFS functionality provides several advantages when dealing with LOB data, including increased efficiency, manageability, and concurrency.

Check whether the filestream property is enabled or not. To do this executes the following query.
SELECT SERVERPROPERTY('FilestreamShareName') ShareName,
SERVERPROPERTY('FilestreamEffectiveLevel') EffectiveLevel,
SERVERPROPERTY('FilestreamConfiguredLevel') ConfiguredLevel


If it is not enable use sp_configure procedure to enable it.
EXEC sp_ configure 'filestream access level', 2;
GO
RECONFIGURE;
GO


FILESTREAM Access Levels:


0. Disable

1. Access via T-SQL only

2. Access via T-SQL only and file system

Once you’ve enabled FILESTREAM support on your SQL Server instance, you have to create a SQL Server file group with the CONTAINS FILESTREAM option. This file group is where SQL Server will store FILESTREAM BLOB files.
Example:
CREATE DATABASE Jobin ON PRIMARY
(
NAME='Jobin_Data',
FILENAME='E:\Jobin\sql\jobin.mdf'
),
FILEGROUP DocumentFileStreamGroup CONTAINS FILESTREAM
(
NAME='FileStreamdocuments',
FILENAME='E:\Jobin\sql\jobin_documents'
)
LOG ON
(
NAME='Jobin_Log',
FILENAME='E:\Jobin\sql\jobin.ldf'
);


To enable FileStream to an existing database execute the following query

-- to add filestream to an existing database
ALTER DATABASE Jobin
ADD FILEGROUP DocumentFileStreamGroup CONTAINS FILESTREAM;
GO
ALTER DATABASE Jobin
ADD FILE
(
NAME = 'FileStreamdocuments'
FILENAME = 'E:\Jobin\sql\jobin_documents'
)
TO FILEGROUP DocumentFileStreamGroup;


FILESTREAM Enabled Tables


Once you’ve enabled FILESTREAM on the server instance and created a FILESTREAM filegroup, you’re ready to create FILESTREAM-enabled tables. FILESTREAM storage is accessed by creating a varbinary (max) column in a table with the FILESTREAM attribute. The FILESTREAM-enabled table must also have a uniqueidentifier column with a ROWGUIDCOL attribute.

CREATE TABLE Employee
(
EmpId UNIQUEIDENTIFIER ROWGUIDCOL PRIMARY KEY,
Name VARCHAR(50),
Document VARBINARY(MAX) FILESTREAM
)


Insert some records into the table.
INSERT INTO Employee VALUES(NEWID(),'Jobin',CAST('jobin john' AS VARBINARY(MAX)));
INSERT INTO Employee VALUES(NEWID(),'Ajith',CAST('Software Engineer' AS VARBINARY(MAX)));


Select the inserted values
SELECT * FROM Employee
SELECT EmpId,Name,CAST(Document AS VARCHAR) AS Document FROM Employee

Monday, October 24, 2011

Introducing Microsoft Visual Studio LightSwitch 2011

Microsoft Visual Studio LightSwitch 2011

Microsoft Visual Studio LightSwitch is a simplified self-service development tool that enables you to build business applications quickly and easily for the desktop and cloud or it is a development tool that helps you build business applications quickly. LightSwitch provides a simplified development environment that enables you to concentrate on the business logic instead of the application infrastructure.

LightSwitch heps us to develop business applications simply and fastly. LightSwitch is optimized around making data and screens, this would reduce the development effort.

Microsoft Visual Studio LightSwitch uses a model-centric architecture for defining, building, and executing a LightSwitch application.

Monday, October 17, 2011

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property


Fix JSON serialization error by setting maxJsonLength.

This error is occured when serialize an object in JSON string by JavaScriptSerializer class, it will throw this exception if object contains too many records(data). We can fix this issue by setting maxJsonLength in web.config file.
Exception type: InvalidOperationException
Exception message: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.


<configuration>
     <system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="50000000"/>
            </webServices>
        </scripting>
    </system.web.extensions>
 </configuration> .

Tuesday, October 4, 2011

Software Development Tips and Tricks & Tutorials

Software Development is the process of creating or developing a quality application which will help the business to grow.

Software development process includes the following steps.
  • Understanding the business or Domain : Now you may have a question that "Why should I know the business/domain?. As a programmer my job is only writing codes and developing the application. then why?". The answer is very simple, if you are aware on the domain, I would say it is definitely an added advantage to the software development process.
  • Understanding requirements: Understanding client requirement is one of the important factor in software development.
  • Design: Once we completed the requirement analysis, next we need to design the application. Mostly its done by creating a high level design document and low level design document.
  • Development: Develop the application based on the design document and functional requirement document. While do coding ensure all business validations and requirements are under coverage.
  • Testing: Testing is an investigation conducted to provide the information about the quality of the product/application.
  • Implementation: In this step, we will be deploying the final solution/application which is tested and completed on to the server. While deploying/releasing we will also develop a release document which will help the end user to deploy the application in their enviornment.
  • Maintanance: Maintanance is the modification of a software product after delivery to correct faults or to improve performance.
I hope now you are clear on the Software Development Life Cycle (SDLC) mentioned above.

Here are some Tips and Tricks that might be improve the quality of software development
  • Love your profession
  • Simplify the complex logic by splitting.
  • Be an innovator and expert in technology
  • Be a good learner
  • Be aware of latest technologies
  • Learn the process
  • Minimum amount of sleep should be 6 hours
  • Be social
  • Enjoy holidays and free time
  • Involve in any games during work hours
  • Think positively.

Sunday, September 4, 2011

Using server-side state management in Asp.Net

Using server-side state management

ASP.NET provides two ways to store state on the server and thus share information between Web pages without sending the data to the client. These two methods are referred to as application state and session state. Application state information is global to the application. It is available to all pages regardless of the user requesting the page. Session state is user-specific state that is stored by the server. It is available only to pages accessed by a single user during a visit to your site.

Application State

Application state in ASP.NET is a global storage mechanism for state data that needs to be accessible to all pages in a given Web application. Application state is optional; it is often not required.

You store application state in an instance of the HttpApplicationState class that is provided through the Page.Application property. This class represents a key–value dictionary, where each value is stored and accessed by its key (or name). You can add to and read from the application state from any page on the server.

Eg: place a button and write the following code.


Application["a"] = Convert.ToInt32(Application["a"]) + 1;
Response.Write("Application value = "+Application["a"]);


Session State


Most Web applications need to store user-specific data between individual requests.

Session state can be thought of in a similar way as application state. The big difference is that session state is scoped to the current browser (or user) session and only available to that session (and not the entire application).

Reading and Writing Session State Data:

You store user-specific session state in the Session object. This is an instance of the HttpSessionState class and represents a key–value dictionary collection. Items are added, updated, and read in a similar manner as working with any .NET dictionary collection.

Eg: place a button and write the following code.

Session["a"] = Convert.ToInt32(Session["a"]) + 1;
Response.Write("Session value = "+Session["a"]);


Disabling Session State


If you don’t use session state, you can improve performance by disabling it for the entire application. You do so by setting the sessionState mode property to Off in the Web.config file. The following shows an example:

<configuration>
<system.web>
<sessionState mode="off"/>
</system.web>
</configuration>


You can also disable session state for a single page of an application by setting the EnableSessionState page directive to False. You can also set the EnableSessionState page directive to ReadOnly to provide read-only access to session variables for the given page.
Eg:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" EnableSessionState = "False"%>


Configuring Cookieless Session State


By default, session state uses cookies to track user sessions. This is the best choice for the vast majority of applications. All modern Web browsers support cookies. However, users can turn them off. Therefore, ASP.NET allows you to enable cookieless session state.

Without cookies, ASP.NET tracks sessions using the URL by embedding the session ID in the URL after the application name and before any remaining file or virtual directory identifier.

You enable cookieless sessions through the Web.config file. Set the cookieless attribute of the sessionState element to true.
<configuration>
    <system.web>
      <sessionState cookieless="true"
      regenerateExpiredSessionId="true" />
    </system.web>
  </configuration>


Choosing a Session State Mode


ASP.NET provides a few different session management modes for your application.

InProc: Stores session state in memory on the Web server. This is the default mode. It offers much better performance than using the ASP.NET State Service or storing state information in a database server.

StateServer: Stores session state in a service called the ASP.NET State Service. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

SQLServer: Stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple servers in a Web farm.

Custom: Enables you to specify a custom session state storage provider. You also need to implement (code) the custom storage provider.

Off: Disables session state. You should disable session state if you are not using it to improve performance.

Tuesday, August 23, 2011

Using Themes in Asp.Net - Example

Using Themes
The Web pages that belong to the same Web site will invariably contain controls that have many properties in common across pages. This includes properties for setting things like background color, font size, foreground color, and other styles. You can manually set the properties for every control on every page in your site. However, that is time consuming, error prone (as you might overlook some settings), and difficult to change (as a change would have to sweep across your entire site). Instead, you can use ASP.NET themes.

ASP.NET themes consist of the following set of elements:

Skins: Skins are files with .skin extensions that contain common property settings for buttons, labels, text boxes, and other controls. Skin files resemble control markups, but contain only the properties you want to define as part of the theme to be applied across pages.

Cascading Style Sheets (CSS ): These are files with .css extensions that contain the style property definitions for HTML markup elements and other custom style classes. A style sheet is linked to a page, master page, or entire site. ASP.NET applies the styles to the page.

Images and other resources: Images (such as a corporate logo) along with other resources can be defined inside a theme. This allows you to switch out the images when you switch themes for a site.

Creating a Theme:

You create themes inside the ASP.NET special folder, App_Themes. This folder sits in your ASP.NET application root. The folder contains separate folders for each theme in your site. You then add the corresponding skins, style sheets, and images to the theme folders.

You need to apply the theme to your site. You can do so at the individual page level by adding the Theme or StyleSheetTheme attribute to the @ Page directive and setting the attribute’s value to the name of your theme (folder name).

Alternatively, you can apply the theme to an entire Web application by adding the

<pages theme="”themeName”">


element or the

<pages stylesheettheme="”themeName”">


element to the Web.config file. This will automatically apply the theme to all pages in your site.

Creating a Skin File

Skin files serve to define default settings for server control appearance attributes. Each server control has attributes for things like font, background color, width, height, and more. Many of these appearance attributes are common among the controls on your site.

A skin file differs from a style sheet in that the skin file uses the attributes of the actual control and not just a set of standard HTML style elements. Skin files contain two types of skins: default and named skins:

Default skins: A default skin automatically applies to all controls of the same type when a theme is applied to a page. A skin is considered a default skin if it does not have a SkinID attribute.

Named skins: A named skin is a control skin with a SkinID property set to a specific name value. Named skins do not automatically apply to controls by type. Instead, you explicitly apply a named skin to a control by setting the ASP.NET control’s SkinID property.

Eg: Default Skins


<asp:Button runat="server" BackColor="#FF3300" BorderStyle="Solid" Font-Bold="True" />


Eg: Named Skins


<asp:Button SkinId="BlueButton" runat="server" BackColor="Blue" BorderStyle="Solid" Font-Bold="True" />


Adding Images to Your Theme
Themes also allow you to switch out the images on your site. This is done through the skin file.

<asp:Image runat="server" SkinId="RedLogo"

ImageUrl="~/App_Themes/RedTheme/RedHead.JPG" />


Adding a Cascading Style Sheet to Your Theme:

A CSS contains style rules that are applied to elements in a Web page. CSS styles define how elements are displayed and where they are positioned on the page.

To add a CSS to your Web site, right-click the name of your theme in Solution Explorer and select Add New Item. You can then select the Style Sheet item template.

body

{
background-color:Black;
}


When the theme is applied to a page, ASP.NET adds a reference to the style sheet to the head element of the page. In the HTML, this reference looks something like the following:

    <link href="SiteStyles.css" rel="themeName/stylesheet" type="text/css" />


Applying a Theme Programmatically:

To apply a theme programmatically, set the page’s Theme property in the Page_PreInit method.
protected void Page_PreInit(object sender, EventArgs e)

{
switch (Request.QueryString["theme"])
{
case "Blue":
Page.Theme = "RedTheme";
break;
case "Pink":
Page.Theme = "PinkTheme";
break;
}
}