Saturday, 31 March 2012

Here are details of ASP.Net Configuration file heirarchy levels : 

Configuration level File name File description
Server Machine.config The file contains the ASP.NET schema for all of the Web applications on the server. This file is at the highest level of the configuration merge hierarchy.
Root Web Web.config The file for the server is stored in the same directory as the Machine.config file and contains default values for most of the system.web configuration sections. At run time, this file is merged second from the top in the configuration hierarchy.
Web site Web.config The file for a specific Web site contains settings that apply to the Web site and inherit downward through all of the ASP.NET applications and subdirectories of the site.
ASP.NET application root directory Web.config The file for a specific ASP.NET application is located in the root directory of the application and contains settings that apply to the Web application and inherit downward through all of the subdirectories in its branch.
ASP.NET application subdirectory Web.config The file for an application subdirectory contains settings that apply to this subdirectory and inherit downward through all of the subdirectories in its branch.
Client application directory ApplicationName.config The file contains settings for a Windows client application (not a Web application).
IIS ApplicationHost.config ApplicationHost.config is the root file of the IIS 7.0 configuration system. It includes definitions of all sites, applications, virtual directories, and application pools, as well as global defaults for the Web server settings. It is in the following location: %windir%\system32\inetsrv\config

Friday, 30 March 2012

By applying style to DIV element we can achieve this.
We can use "overflow" property of style.
Overflow property has different values like auto , hidden , scroll, visible

Here are example for this.

Example :
 <div style="height: 50px; overflow: auto; width: 100px">
        vb.net<br />
        c#.net<br />
        SQL SERVER<br />
        JAVA<br />
        JAVA Script<br />
        LINQ<br />
        MVC<br />
        Silver Light<br />
        Oracle<br />
    </div>

Output: 

vb.net
c#.net
SQL SERVER
JAVA
JAVA Script
LINQ
MVC
Silver Light
Oracle

Here overflow:auto means scroll is only visible when needed.

Wednesday, 28 March 2012

Local temporary tables are visible only in to their creators during the same connection to an instance of SQL Server as when the tables were first created or referenced.
Local temporary tables are deleted after disconnects from SQL Server instance .
Global temporary tables are visible to any user and any connection after they are created,
and are deleted when all users that are referencing the table disconnect from the instance of SQL Server.

You can create tables using following syntax.

Table Variable :
          DECLARE @tmp TABLE

Table variables are only visible to the the connection that creates it, are stored in RAM,
and are deleted after the batch or stored procedure ends.

Local temporary tables :
          CREATE TABLE #tmp

Local temporary tables are only visible to the connection that creates it,
and are deleted after the connection is closed.

Global temporary tables :
          CREATE TABLE ##tmp

Global temporary tables are visible to everyone, and are deleted after the connection that created it is closed.

Tempdb permanent tables :
          USE tempdb CREATE TABLE tmp

Tempdb permanent tables are visible to everyone, and are deleted when the server is restarted.

Local Table can not be shared between multiple users.
Global Table can be shared between multiple users.

Write in comment if you know more differences. I will add this in my blog.

Tuesday, 27 March 2012

You can able to enumerate an enum to get it's values and names.
Example :
We have an emum Called "Sports".
   Public Enum Sports
        Cricket
        Hockey
        Soccer
        BaseBall
        Tennis
    End Enum

You can enumerate this by Values and by Names.

Following code demostrate how you can enumerate by Values.
Example :
   For Each strValue As String In [Enum].GetValues(GetType(Sports))
            Response.Write(strValue.ToString())
            Response.Write("</br>")
   Next

Following code demostrate how you can enumerate by Names.
Example :
  For Each strName As Object In [Enum].GetNames(GetType(Sports))
            Response.Write(strName.ToString())
            Response.Write("</br>")
  Next

Tuesday, 20 March 2012

Click Here to Download Sample ThreadWasBeingAbortedExample.zip
Note : In this sample application there is two pages First page "ErrorSample.aspx" This page dmostrate how this error occured you can check this by putting debug point in Catch section, you notice that when Response.Redirect method called after that error thow and page is being redirected. Second page is "ErrorResolvedExample.aspx" in this page we demostrate how to resolve this issue.

When you are using Response.End, Response.Redirect, or Server.Transfer method methods in Try Catch Block it will throw "ThreadAbortException" Exception.
Error Message like "Thread was being aborted."

The Reason for this error due to.
The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline.
The line of code that follows Response.End is not executed.

This problem occurs in the Response.Redirect and Server.Transfer methods because both methods call Response.End internally.

Solution for this Problem is as follows.

For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method
instead of Response.End to bypass the code execution to the Application_EndRequest event.

Example :
HttpContext.Current.ApplicationInstance.CompleteRequest();

For Response.Redirect, use an overload, Response.Redirect(String url, bool endResponse) Method.
Pass false for the end Response parameter to suppress the internal call to Response.End.

Example :
 Response.Redirect ("otherpage.aspx", false);

For Server.Transfer, use the Server.Execute method instead.

Example :
Server.Execute("otherpage.aspx");

Monday, 19 March 2012

If you want to use FILESTREAM data storage features in database you must create FILESTREAM enabled database.
Must specify the CONTAINS FILESTREAM clause for at least one filegroup.

Here are the sample script to create FILESTREAM-Enabled Database :
CREATE DATABASE AccountSystem
ON
PRIMARY ( NAME = accountsystem1,
    FILENAME = 'c:\data\accountsystemdat1.mdf'),
FILEGROUP FileStreamGroup1 CONTAINS FILESTREAM( NAME = accountsystem3,
    FILENAME = 'c:\data\filestream1')
LOG ON  ( NAME = Archlog1,
    FILENAME = 'c:\data\accountsystemlog1.ldf')
GO

Here this script Create Database name "AccountSystem".
This database contains three filegroups PRIMARY ,  accountsystem1 AND FileStreamGroup1.
PRIMARY  and accountsystem1 are regular file groups that cannot contain FILESTREAM data.
FileStreamGroup1 is the FILESTREAM filegroup.

For a FILESTREAM filegroup, FILENAME refers to a path. The path up to the last folder must exist, and the last folder must not exist.
In this example, c:\data must exist. However, the filestream1 subfolder cannot exist when you execute the CREATE DATABASE statement.

After you run this script, a filestream.hdr file and an $FSLOG folder appears in the c:\Data\filestream1 folder.
The filestream.hdr file is a header file for the FILESTREAM container.

Important
The filestream.hdr file is an important system file. It contains FILESTREAM header information. Do not remove or modify this file.

You can use the ALTER DATABASE statement to add a FILESTREAM filegroup for an exsiting database.

Saturday, 17 March 2012

FILESTREAM storage is use to store unstructured data, such as documents and images, on the file system.
Before we can start to use FILESTREAM, you must enable FILESTREAM on the instance of the SQL Server Database Engine.
Here are describes how to enable FILESTREAM by using SQL Server Configuration Manager.

Important Note :
You cannot enable FILESTREAM on a 32-bit version of SQL Server running on a 64-bit operating system.

Step enable and change FILESTREAM settings
  1. Open SQL Server Configuration Manager from Microsoft SQL Server 2008 R2 's  Configuration Tools Menu  .
  2. In the list of services, right-click SQL Server Services, and then click Open.
  3. In the SQL Server Configuration Manager snap-in, locate the instance of SQL Server on which you want to enable FILESTREAM.
  4. Right-click the instance, and then click Properties.
  5. In the SQL Server Properties dialog box, click the FILESTREAM tab.
  6. Select the Enable FILESTREAM for Transact-SQL access check box.
  7. If you want to read and write FILESTREAM data from Windows, click Enable FILESTREAM for file I/O streaming access. Enter the name of the Windows share in the Windows Share Name box.
  8. If remote clients must access the FILESTREAM data that is stored on this share, select Allow remote clients to have streaming access to FILESTREAM data.
  9. Click Apply.
  10. In SQL Server Management Studio, click New Query to display the Query Editor.
  11. In Query Editor, enter the following Transact-SQL code:
    EXEC sp_configure filestream_access_level, 2
    RECONFIGURE
  12. Click Execute.
  13. Restart the SQL Server service.

Friday, 9 March 2012

Here are varios functions to get system date and time.

SELECT SYSDATETIME() AS 'SYSDATETIME'
Output :-
2012-03-09 12:01:17.25

SELECT SYSDATETIMEOFFSET() AS 'SYSDATETIMEOFFSET'
Output :-
2012-03-09 12:01:17.2580000 +00:00

SELECT SYSUTCDATETIME() AS 'SYSUTCDATETIME'
Output :-
2012-03-09 12:01:17.25

SELECT CURRENT_TIMESTAMP AS 'CURRENT_TIMESTAMP'
Output :-
2012-03-09 12:01:17.257

SELECT GETDATE() AS 'GETDATE'
Output :-
2012-03-09 12:01:17.257

SELECT GETUTCDATE() AS 'GETUTCDATE'
Output :-
2012-03-09 12:01:17.257

Friday, 2 March 2012


Sql Serve 2008 introduce new Date and Time data types.
Here are the list of new datatypes:

SQL Server 2008 data type Default string literal format
time hh:mm:ss[.nnnnnnn]
date YYYY-MM-DD
datetime2 YYYY-MM-DD hh:mm:ss[.nnnnnnn]
datetimeoffset YYYY-MM-DD hh:mm:ss[.nnnnnnn] [+|-]hh:mm 

Here are Comparison between date and time datatypes.

Query :
SELECT
     CAST('2012-03-02 12:40:39. 1234567 +12:10' AS time(7)) AS 'time'
    ,CAST('2012-03-02 12:40:39. 1234567 +12:10' AS date) AS 'date'
    ,CAST('2012-03-02 12:40:39.123' AS smalldatetime) AS
        'smalldatetime'
    ,CAST('2012-03-02 12:40:39.123' AS datetime) AS 'datetime'
    ,CAST('2012-03-02 12:40:39. 1234567 +12:10' AS datetime2(7)) AS
        'datetime2'
    ,CAST('2012-03-02 12:40:39.1234567 +12:10' AS datetimeoffset(7)) AS
        'datetimeoffset';

Here are the output of the query:
SQL Server 2008 data type Output
time 12:40:39.1234567
date 2012-03-02
smalldatetime 2012-03-02 12:41:00
datetime 2012-03-02 12:40:39.123
datetime2 2012-03-02 12:40:39.1234567
datetimeoffset 2012-03-02 12:40:39.1234567 +12:10

Thursday, 1 March 2012

You can also insert ListItem at specific location.
In .Add Method Items are append.
There is one method ".Insert" to insert items as specified location.

Syntax :
DropDownList.Items.Insert(index as integer , System.Web.Ui.WebControls.ListItem)
Hear index is based on zero.

Example :
        Dim objListItem As ListItem
        objListItem = New ListItem("Software", 1)
        ddlProduct.Items.Insert(1, objListItem)

In this example the item is inserted at 2nd place because index is zero based.