Wednesday, December 31, 2014

Visual Studio 2015 Improvements for .NET, works with new .NET framework 4.6

Below are some new features of Visual Studio 2015
  • PerfTips
              PerfTips allow you to quickly and easily see performance bottlenecks as you are debugging your application.
  • Intuitive Breakpoint Settings
            The new and intuitive breakpoint settings make it a lot easier to change the behavior of breakpoints.
  • Setting breakpoints on auto-implemented properties
              Debug support for auto-implemented properties
  • Lambdas in the debugger windows
              Lambdas are now supported in debugger windows
  • Core IDE and Editing Improvements
              New enhanced core IDE and editing experiences for C# and Visual Basic

.NET 2015 also trying to remove some known differences of VB and C#.NET and bring the two languages closer. It is really good initiative to remove differences between languages, specially between VB and C#.Net

Thursday, December 18, 2014

Error: WCF - Cannot find the X.509 Certificate using the following search criteria...

I was getting this error when I have below lines of code on my WCF web.config file

"serviceCertificate findValue="WCfServer" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName""

I have installed Server and Client certificate into MMC >> Personal and Trusted People but still when I try to browse my service from IIS I am getting same 'X.508 certificate...' error.

Solution

I found the issues, My app pool account in IIS was running under "ApplicationPoolIdentity" but since on my web.config and certificate installation done using "Current User",  So it is important to run your app pool account under your local Identity user Id. So I just change App pool account in IIS to run under my local window credential and it works for me. 

.NET New Feature, SOLID Principal and WCF Security

.NET Framework 4.5 new Features
  • Async and await (code markers)
  • Zip facility (Zip compression)
  • Regex timeout (TimeOut)
  • Profile optimization (Improved startup performance)
  • Garbage collector (GC background cleanup)


SOLID Architecture Principal
  • “S” - SRP (Single responsibility principle)
  • “O” - Open closed principle
  • “L”- LSP (Liskov substitution principle)
  • “I” - ISP (Interface Segregation principle)
  • “D” - Dependency inversion principle.


WCF Security
  • WCF Security Transport vs Message using BasicHttpBinding and wcHttpBinding
  • Difference between Transport and Message Security
  • Difference between BasicHttpBinding and wcHttpBinding Binding
  • How to create certificates
  • Example C# code to implement Transport based security and Message based Security
  • Eenable Windows authentication on WCF using ‘BasicHttpBinding’

Tuesday, November 18, 2014

Update your Window phone (Samsung Focus SGH-i197) to from Window 7.5 to 7.8 (7.10.8862.144)

Update your Window phone (Samsung Focus SGH-i197) to from Window 7.5 to 7.8 (7.10.8862.144)

It works for me for my Samsung Focus SGH-i197. Be patient it may take around 45 min. it will restart your phone multiple times, update will start from 7.10.8112.7 and go till 7.10.8862.144 final version. you installation only complete when "Congratulation! you'r done!" message box pops up. then you can close the application.

Download below two files from below link and follow the given instruction

Sunday, November 16, 2014

Update your Samsung SGH-i197 window phone from 7.10.7720 to 7.10.8101.79 without Zune forcefully

Below steps works for me on my Window Phone (Samsung SGH-i197) having OS 7.10.7720

Step-1
Count Display Language in your phone, Go to Setting >> Language

Step-2
Download files based on language in your phone.
Here are the individual languages that you need to download to the same directory as the OS install files from above English (US) language pack Chinese (traditional), Chinese (simplified), GermanCzechFrenchEnglish – UK, Spanish, Danish, Greek, Finnish, Hungarian, Italian, Japanese, Korean, Dutch, Norwegian, Polish,Portuguese – (Brazil), Russian, Swedish, Portuguese – (Portugal)
If you need all 22 in one shot, just download this file. Do NOT install extra languages.
Step-3
Download the ZIP file here and keep in in your local PC drive (i.e. C:\Phone)

Step-3
Download and install the appropriate file based on your PC OS version
Step-4
Follow below steps
1.    Make sure your phone is charged to at least 50%
2.    Plug your phone via USB into your computer and close Zune Desktop (yes, close it)
3.    On your computer, navigate to where you extracted the OS update: Cab Sender --> Tools --> x86/x64(Choose one based off your system architecture)
4.    Run UpdateWP.exe (Note: you should see a DOS screen flash and disappear)
5.    Back out to your main directory and run WP7 Update Cab Sender.bat
6.    Choose 'B' (This will back up your device to Zune, then install the updates)

Reference Site: See below site for more details and troubleshoots

To update Window 7.5 to 7.8 (7.10.8862.144) please see below link
http://riteshkk2000.blogspot.com/2014/11/update-your-window-phone-samsung-focus.html

Thanks for
     

Saturday, November 15, 2014

Multiple ways to Export data into Excel using .net and SQL server

There are many ways to export data into excel, need to analyze following requirement before choosing any methods like:
  • Volume of data,
  • Dynamic behavior,
  • Schedule export or Manual export
  • Performance & Scalability
  • Security
  • Operating system, (32 or 64 bit etc.)

Based on above requirement you can decide best approach for export. I would suggest create proof of concept and do your entire requirement testing carefully before taking final decision.

1. Export data using Microsoft Office.Interop Library


Microsoft .NET provides Interop library to create excel object and export data table or data grid view into excel sheet, this object is very useful when you require designing fancy excel sheet using all excel features; like: cell design, formula, header & footer design etc.

           
Pros:
                    - Complete programming support to Excel via C#
                    - Integrated with to Visual studio

Cons:
                    -You must have Excel installed on your system for this code to run properly.
                    -To use COM interop, you must have administrator or Power User security permissions
                    -It is little slow to handle heavy data load and not enough to load large size of
dataset
. 
2. Export data using OpenXML SDK 2.0

Open XML SDK 2.0 lets developers be more productive by providing design-time capabilities such as IntelliSense support and a type-safe development experience. You can download from Download SDK.


Pros:
                 -Doesn't require Microsoft Office installed
                 -Made by Microsoft , decent MSDN documentation
                 -Just one .Net dll require to use in project
                 -SDK comes with many tools like diff, validator, etc.            
                 -The SDK is stable and it is supported by Microsoft.
                 -LINQ can be used to navigate data of excel file.
                 -It performs operations with just a few lines of code.

Cons:
                 -It supports only the documents created in Office 2007 or later (i.e. xlsx, docs etc)
                 -It cannot render Office functions. You can't do Excel calculations rendering on                       the server-side. 

3. Export data in CSV file using StreamWtiter

If you requirement to just export the data into plain excel file, single sheet, no column formatting needed then you should go with CSV file creation instead of Excel. This solution works very well with large size of data. Tested with 1 million rows with file size around 2 GB.

Pros:
                -No Extra DLL require
                -Faster than creating excel file
                -Can handle large data size

Cons:
                -Creates single excel sheet only
                -No formatting support
                -Need to remove special char like: “’,” (Comma) 


Public string RemoveInvalidChar(string input)
{
  List<string> invalidItems = new List<string>()
  {
      ",", "/r", System.Environment.NewLine
  };

  foreach (string invalidItem in invalidItems)
  {
    input = input.Replace(invalidItem, "");
  }
   return input;
}

private void btnExport_Click(object sender, EventArgs e)
{
    int cols;
    //open file
    StreamWriter wr = new System.IO.StreamWriter(@"C:\PerformanceTest.csv", false, Encoding.UTF8);
    //Create datatable having huge rows and columns
    DataTable dt = GetDataTable();
    //determine the number of columns and write columns to file
    cols = dt.Columns.Count;
    for (int i = 0; i < cols; i++)
    {
        wr.Write(dt.Columns[i].ToString().ToUpper() + ",");
    }
        wr.WriteLine();
    //write rows to excel file
    for (int i = 0; i < (dt.Rows.Count); i++)
    {
      for (int j = 0; j < cols; j++)
      {
        if (dt.Rows[i][j] != null)
         {
           wr.Write(RemoveInvalidChar(dt.Rows[i][j].ToString()) + ",");
         }
         else
         {
          wr.Write(",");
         }
        }
        wr.WriteLine();
      }
      //close file
      wr.Close();
   }
 }

4. Export data using OLEDB provider

The basic format for the Microsoft.Jet.OLEDB.4.0 provider is: [32-bit SQL Server for Excel 2003]
Export:
INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=c:\contact.xls;',
'SELECT * FROM [Sheet1$]')
SELECT TOP 5 doc_id,doc_name FROM document
Import:
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
  'Excel 8.0;Database=C:\excel-sql-server.xls', [Sheet1$])
SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
  'Data Source=C:\excel-sql-server.xls;Extended Properties=Excel 8.0')...[Sheet1$]
The basic format for the Microsoft.ACE.OLEDB.12.0 provider is:[64-bit SQL Server for any Excel files or 32-bit SQL Server for Excel 2007]
Export:
INSERT INTO OPENROWSET ('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=c:\contact.xls;',
'SELECT * FROM [Sheet1$]')
SELECT TOP 5 doc_id,doc_name FROM document
Import:
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
  'Excel 12.0;Database=C:\excel-sql-server.xlsx', [Sheet1$])
SELECT * FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0',
  'Data Source=C:\excel-sql-server.xlsx;Extended Properties=Excel 12.0')...[Sheet1$]

Note:     
   -Microsoft.Jet.OLEDB.4.0 and Microsoft.ACE.OLEDB.12.0 has to be registered.
   -Microsoft.ACE.OLEDB.12.0 provider work with SQL Server x64 for any Excel             version files.
How to registered OLEDB
#1: Manually register those DLLs.
  1. Go to Start->Run and type cmd
  2. this starts the Command Prompt
  3. (also available from Start->Programs->Accessories->Command Prompt)
  4. Type cd .. and press return
  5. Type cd .. and press return again (keep doing this until the prompt shows :\> )
  6. Now you need to go to a special folder which might be c:\windows\system32 or it might be c:\winnt\system32 or it might be c:\windows\sysWOW64

        try typing each of these e.g.
             cd c:\windows\sysWOW64
             (if it says The system cannot find the path specified, try the next one)
             cd c:\windows\system32
             cd c:\winnt\system32  
        When one of those doesn't cause an error, stop, you've found the correct                     folder
    7. Now you need to register the OLE DB 4.0 DLLs by typing these commands and           pressing return after each
  • regsvr32 Msjetoledb40.dll
  • regsvr32 Msjet40.dll
  • regsvr32 Mswstr10.dll
  • regsvr32 Msjter40.dll
  • regsvr32 Msjint40.dll

#2:  Open the project in Visual Studio then:
  • From the solution explorer right-click your project then click Properties
  • Click the Build tab
  • Change Platform target from: Any CPU to x86
  • Re-build your solution


Wednesday, September 03, 2014

Error: Incorrect syntax near the keyword 'AS' on SQL Server 2005.

Error: Incorrect syntax near the keyword 'AS' on SQL Server 2005.

I got this error when I created SQL script from SQL Server 2008 and tried to run on SQL Server 2005.

CREATE TYPE EmployeeIDType AS TABLE
(
   ID         Int
)
GO

Cause: Table Type is not supported by SQL Server 2005, Table type introduced in new version of SQL Server 2008 and above.

AlterNet way to fulfill table type parameter requirement in SQL Server 2005 is to pass XML or use NVARCHAR(MAX) as input parameter

SQL Server 2005

Oracle

Tuesday, August 05, 2014

After Window 8 upgrade system running very slow, Disk usage 100%

I had window 7 and I upgrade to window 8, I found my system running very very slow and on task manager disk usage is around 100%. I did following steps to resolved this issues, now disk usage is 5 to 10% when ideal.

  • Press windows + R key 
  • Select the option "Control Panel"  > "System and Security" > "System".
  • Click on "Advanced system settings".
  • Under performance, click on "Settings".
  • Go to Advanced tab, Under Virtual memory, click on "Change".
  • un-check "Automatically manage paging file size for all drives" check box.
  • Select your windows drive (where OS is installed).
  • Click on Custom size radio button.
  • Set Initial size equivalent to your RAM size in MB. (ex; if 4 GB RAM then type 4000)
  • Set Maximum size to twice of your RAM size in MB. (ex; if 4 GB RAM then 8000)
  • Click on Set and Click on OK to close all window.



Thursday, July 31, 2014

Error: "Unable to get property 'UI' of undefined or null reference" when using ModalPopupExtender

I was using below code combination for opening model popup control, while run time I got this error.

asp:ScriptManager
asp:ModalPopupExtender

To resolve this error I just replaced "asp:ScriptManager" tag with "asp:ToolkitScriptManager" and it's works for me.

asp:ToolkitScriptManager
asp:ModalPopupExtender

Thursday, July 24, 2014

HTML 5 Offline Support (Manifest) and Local Storage example with Visual Studio

HTML 5 Offline Support (Manifest) and Local Storage example with Visual Studio

HTML5 storage enables a site to work offline and ability to provide a local cache for data on the server but not subject to frequent change.
HTML5 storage supports two types of storages LocalStorage and SessionStorage. First is designed as a long-term storage mechanism for data that spans sessions and time and second is only persistent for the life of a particular user session.
LocalStorage is great for relatively static files or database tables, to increase performance especially when offline versions of the data needed.
You can download your required pages when you are online. If network connectivity goes off, HTML 5 offline application will automatically serves the offline web pages which you have downloaded when you were online.

Browser Supports for Offline and Local Storage:              
  • IE (8.0+)
  • FIREFOX (3.5+)
  • SAFARI (4+)     
  • CHROME (4+)
  • OPERA (10.5+)
  • IPHONE (2.0+)
  • ANDROID (2.0+)
Manifest file items:
  • JavaScript
  • Web pages
  • CSS
  • Images
  • etc.
Manifest files sections:
  • CACHE
  • NETWORK
  • FALLBACK
CACHE section: Declare files to be cached. Files will be served from the cache, even if application is online.
NETWORK section: Declare files that browser should try to download from the server, regardless of whether the user is online or offline.
FALLBACK section: Define fallback resources to be used when the application is offline.

Storage Capacity: 5 MB

Consolidate links to learn Offline and local storage features of HTML 5: