Tuesday, December 30, 2008

ADO .Net Namespaces, Providers and use of XML

ADO Data Provider:


A data provider is a set of ADO.NET classes that allows you to access a specific database, execute SQL commands, and retrieve data. Essentially, a data provider is a bridge between your application and a data source.


The classes that make up a data provider include the following:


Connection: You use this object to establish a connection to a data source.
Command: You use this object to execute SQL commands and stored procedures.
DataReader: This object provides fast read-only, forward-only access to the data retrieved from a query.
DataAdapter: This object performs two tasks. First, you can use it to fill a DataSet (a disconnected collection of tables and relationships) with information extracted from a data source. Second, you can use it to apply changes to a data source, according to the modifications you’ve made in a DataSet.



XML and ADO.NET:


ADO.NET leverages the power of XML to provide disconnected access to data. ADO.NET was designed hand-in-hand with the XML classes in the .NET Framework — both are components of a single architecture.


ADO.NET and the XML classes in the .NET Framework converge in the DataSet object.

The DataSet can be populated with data from an XML source, whether it is a file or an XML stream.

The DataSet can be written as World Wide Web Consortium (W3C) compliant XML, including its schema as XML Schema definition language (XSD) schema, regardless of the source of the data in the DataSet.


Because the native serialization format of the DataSet is XML, it is an excellent medium for moving data between tiers making the DataSet an optimal choice for remoting data and schema context to and from an XML Web service.



ADO Namespaces:


Below are few namespaces those are used in ADO .Net for making connections to database, playing with different databases e.g. SQL, Oracle.


System.Data: Contains the key data container classes that model columns, relations, tables, datasets, rows, views, and constraints. In addition, contains the key interfaces that are implemented by the connection-based data objects.


System.Data.Common: Contains base, mostly abstract classes that implement some of the interfaces from System.Data and define the core ADO.NET functionality. Data providers inherit from these classes to create their own specialized versions.


System.Data.OleDb: Contains the classes used to connect to an OLE DB provider, including OleDbCommand, OleDbConnection, and OleDbDataAdapter. These classes support most OLE DB providers but not those that require OLE DB version 2.5 interfaces.


System.Data.SqlClient: Contains the classes you use to connect to a Microsoft SQL Server database, including SqlDbCommand, SqlDbConnection, and SqlDBDataAdapter. These classes are optimized to use the TDS interface to SQL Server.


System.Data.OracleClient: Contains the classes required to connect to an Oracle database (version 8.1.7 or later), including OracleCommand, OracleConnection, and OracleDataAdapter. These classes are using the optimized Oracle Call Interface (OCI).


System.Data.Odbc: Contains the classes required to connect to most ODBC drivers. These classes include OdbcCommand, OdbcConnection, and OdbcDataAdapter. ODBC drivers are included for all kinds of data sources and are configured through the Data Sources icon in the Control Panel.


System.Data.SqlTypes: Contains structures that match the native data types in SQL Server. These classes aren’t required but provide an alternative to using standard .NET data types, which require automatic conversion.



Thanks & Regards,


Paresh Bhole

Thursday, November 27, 2008

Compatibility with IE-8

Hi,

This is regarding the “compatibility with IE-8”. We have two different ways to configure IE 8 to emulate/render the web site like IE 7 without any GUI & JavaScript issues.


First one using IE 8 browsers provides way to open web site exactly similar to IE 7:

To confirm that browsing in Internet Explorer 8 Standards mode is the cause of an issue, follow these steps:

  1. Open Internet Explorer 8 Beta 1.

    Note If you do not have Internet Explorer 8 Beta 1 installed, you can download it from the following Microsoft Web site:

http://www.microsoft.com/windows/products/winfamily/ie/ie8/getitnow.mspx (http://www.microsoft.com/windows/products/winfamily/ie/ie8/getitnow.mspx)

  1. Click Emulate IE 7 on the menu bar, and then close the Internet Explorer browser window.
  2. Open Internet Explorer 8 Beta 1, verify that the Emulate IE 7 button is depressed, and then visit the affected Web site.
  3. Make sure that the affected Web site is now displayed correctly.
  4. Click Emulate IE 7 to disable Internet Explorer 7 emulation, and then close the Internet Explorer browser window.
  5. Open Internet Explorer 8 Beta 1, and then visit the affected Web site to confirm that you experience the issues again after disabling Internet Explorer 7 emulation.



Second way is to use Meta-Tag:


You can use one of the following options to force Internet Explorer 8 to render Web pages like Internet Explorer 7:


· Per-site basis



Site owners and administrators can include the following custom HTTP header to force Internet Explorer 8 to render Web pages like Internet Explorer 7:


X-UA-Compatible: IE=EmulateIE7



To add a custom HTTP response header at the Web site level in Internet Information Services 7 on a Windows Server 2008-based computer, follow these steps:

    1. Click Start, click Administrative Tools, and then click Internet Information Services (IIS) Manager.
    2. Under Connections, double-click the server that you want, and then double-click Sites.
    3. Click the Web site where you want to add the custom HTTP response header.
    4. Under Web site name Home, double-click HTTP Response Headers in the IIS section.

      Note In this step, Web site name is the name of the Web site.
    5. Under Actions, click Add.
    6. In the Name box, type X-UA-Compatible.
    7. In the Value box, type IE=EmulateIE7.
    8. Click OK.

To add a custom HTTP response header at the Web site level in Internet Information Services 6 and earlier versions, follow these steps:

    1. Click Start, click Run, type inetmgr.exe, and then click OK.
    2. Expand the server that you want, and then expand Web Sites.
    3. Right-click the Web site that you want, and then click Properties.
    4. Under Custom HTTP headers, click Add.
    5. In the Custom header name box, type X-UA-Compatible.
    6. In the Custom header value box, type IE=EmulateIE7.
    7. Click OK two times.


· Per-page basis



Site owners and administrators can include the following special HTML tag after the tag on the page:



The following example shows use of this Internet Explorer 7 compatibility mode tag on a per-page basis:

  
  
  My Web Page
  

Content goes here.




· Testing your site with the meta-tag



To verify you have installed the tag correctly on your site, follow these steps:

    1. If you do not have Internet Explorer 8 Beta 1 installed, you can download it from the following Microsoft Web site:

http://www.microsoft.com/windows/products/winfamily/ie/ie8/getitnow.mspx (http://www.microsoft.com/windows/products/winfamily/ie/ie8/getitnow.mspx)

    1. Download the Internet Explorer 8 Beta 1 security update that is described in Microsoft Knowledge Base article 951804. This update adds support for the IE=EmulateIE7 tag. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

951804 (http://support.microsoft.com/kb/951804/ ) MS08-031: Security update for Internet Explorer 8 Beta 1


For more information about the EmulateIE7 tag, visit the IEBlog Web site:

http://blogs.msdn.com/ie/archive/2008/06/10/introducing-ie-emulateie7.aspx (http://blogs.msdn.com/ie/archive/2008/06/10/introducing-ie-emulateie7.aspx)

    1. Browse your site in Internet Explorer 8 Standards mode and verify you do not encounter issues described in the "Symptoms" section.


Thanks,

Paresh B

Wednesday, November 19, 2008

Image Editor



Hi All,


Lots of time we used to develop image resizing code (creating thumbnail or resizing image to required height & width), but keeps on forgetting the code, even happen with me too. This code is not actually written by me, but posted here for future references.


This code is posted to keep the code for resizing & sacing an image uploaded.


Resize Image:


Below method shows the code to resize an uploaded image.


Parameters:

  1. (Bitmap imgToResize)[ System.Drawing.Image] – This is an actual image uploaded or provided for resizing.
  2. (Size size) – This is the size of the new resized image.


Code:

  1. The next step is to actually figure out what the size of the resized image should be. The first step is to calculate the percentages of the new size compared to the original. Next we need to decide which percentage is smaller because this is the percent of the original image we will use for both height and width. And now we calculate the number of height and width pixels for the destination image.
  2. The final thing to do is create the bitmap (System.Drawing.Bitmap) which we will draw the resized image on using a Graphics (System.Drawing.Graphics) object. I also set the interpolation mode, which is the algorithm used to resize the image. I prefer HighQualityBicubic, which from my testing seems to return the highest quality results. And just to clean up a little I dispose the Graphics object.


public static Bitmap ResizeImage(Bitmap imgToResize, Size size)

{

int sourceWidth = imgToResize.Width;

int sourceHeight = imgToResize.Height;

float nPercent = 0;

float nPercentW = 0;

float nPercentH = 0;


nPercentW = ((float)size.Width / (float)sourceWidth);

nPercentH = ((float)size.Height / (float)sourceHeight);


if (nPercentH <>

nPercent = nPercentH;

else

nPercent = nPercentW;


int destWidth = (int)(sourceWidth * nPercent);

int destHeight = (int)(sourceHeight * nPercent);


Bitmap b = new Bitmap(destWidth, destHeight);

Graphics g = Graphics.FromImage((Image)b);


g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);

g.Dispose();

return (Bitmap)b;

}


Save Image Code:


Below method will save the resized image to the given path.

  1. (string path) – Mapped path for saving image with Image Name.
  2. (Bitmap img) [System.Drawing.Image] – This is an actual image.
  3. (long quality) – This parameter used like number of pixels.


public static void SaveJpeg(string path, Bitmap img, long quality)

{

// Encoder parameter for image quality

EncoderParameter qualityParam =

new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);

// Jpeg image codec

ImageCodecInfo jpegCodec = getEncoderInfo("image/jpeg");


if (jpegCodec == null)

return;


EncoderParameters encoderParams = new EncoderParameters(1);

encoderParams.Param[0] = qualityParam;

img.Save(path, jpegCodec, encoderParams);

}



private static ImageCodecInfo getEncoderInfo(string mimeType)

{

// Get image codecs for all image formats

ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

// Find the correct image codec


for (int i = 0; i <> if (codecs[i].MimeType == mimeType)

return codecs[i];

return null;

}



Thanks,

Paresh Bhole

Tuesday, October 21, 2008

Session, ViewState, Cache, Application


Session

View State

Cache

Application

Modes

In-Proc,

State Server,

SQL Server

-

Page Output Cache,

Fragment Cache,

Data Cache,

Data Source Cache

-

Dependency

Cookie – if not a cookie less to store Session ID.

e.g. ASP.NET_SessionId cookie gets created.

Cookie less – URL append with Session Id.

SQL Cache Dependencies,

File,

Query String Key

Storage Location

Data is stored in memory (in process),

Web Server.

Page (but can be modified to overwrite the storage mechanism to
store viewstate else where, esp. Session, Application, File or DataBase)

Data is stored in memory (in process),

Web Server

Data is stored in memory (in process),

Web Server

Can Store

Complex Objects & Any Data

e.g. DataSet

Any serializable class to View State.

e.g. Strings, DateTimes, and Integers

Page Output, Complex Object (e.g. DataSet),

Note

Anything that you add to View State must be added to the hidden __VIEWSTATE form field. If this field gets too big, it can have a significant impact on your page's performance.

View State is loaded after the Page InitComplete event, and View State is saved after the Page PreRenderComplete event. This means that you should not attempt to retrieve a value from View State before or during the InitComplete event. You also should not attempt to add a value to View State after the PreRenderComplete event.

Application state is little used in ASP.NET applications. In most cases, you should use the Cache object instead of Application state because the Cache object is designed to manage memory automatically.

Thanks,

Paresh Bhole

Hello

Thanks for checking out my post...

... Paresh Bhole