Tuesday, March 17, 2009

String.Format(“{0:X}”, args[]) Function : C#.Net

Example: String.Format("{0:D}", DateTime.Now) = 17 Mar 2009
SymbolTypeRepresentation
CCurrency:(123.00)
DDecimal-123
EScientific-1.234500E+002
FFixed point-123.45
GGeneral (default)-123 (default = 'G')
NNumber-123.00
PPercent-12,345.00 %
RRound-trip-123.45
XHexadecimalFFFFFF85
Date Time Formatting
SymbolTypeRepresentation
dShort date07/09/2007
DLong dateMonday, 09 July 2007
tShort time13:42
TLong time13:42:50
fFull date/short timeMonday, 09 July 2007 13:42
FFull date/long timeMonday, 09 July 2007 13:42:50
gGeneral date/short time07/09/2007 13:42
GGeneral date/long time (default)07/09/2007 13:42:50 (default = 'G')
MMonthJuly 20
RRFC1123Mon, 09 Jul 2007 13:42:50 GMT
sSortable2007-07-09T13:42:50
uUniversal sortable2007-07-09 13:42:50Z (invariant)
UUniversal fullMonday, 09 July 2007 20:42:50
YYear2007 July
Standard Enumeration Formatting
GGeneral (default)Green (default = 'G')
FFlagsGreen (flags or integer)
DDecimal number3
XHexadecimal00000003



Friday, February 27, 2009

Login Failed The user is not associated with a trusted SQL Server connection: SQL Server 2005


This occurs when you try to login using SQL Server user cardinals without configuring SQL Server to use Windows and SQL Server authentication.

Resolution:

[1] Open SQL Server management studio – [2] Login to SQL server using windows authentication – [3] Right click on SQL Server instance and go to properties – [4] Expand security tab and select 'SQL Server and Windows authentication mode' under 'Server Authentication'

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding - Microsoft SQL Server 2005


Symptom:

SQL Server throws an exception 'Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. (Microsoft SQL Server, Error: -2) when try to connect from a remote computer. Most probable symptom for the error is TCP Port 1433 being blocked by the windows firewall in a computer running windows XP(SP2).

Solution

Scenario 1

Make sure you have enabled remote connections from the SQL Server surface area configuration and allow TCP/IP, Named Pipe protocol or combination as necessary.

  • To Enable Remote connections: [1] SQL Server 2005 – [2] Configuration Tools – [3] SQL Server Surface area configuration – [4] Click on 'Surface area configuration for services and connections'.
  • Expand [1] Database Engine – [2] Remote Connections – [3] Select Local and remote connections – [4] Select the desired protocol (In this scenario I have used TCP/IP and Named Pipes)
  • Restart the SQL Server.
Scenario 2

Open TCP Port 1433 – This is the default port that SQL server use for remote connections. By default windows XP firewall deny access of this port:

  • Open [1] Control Panel – [2] Windows Firewall – [4] Click on 'Add Port'
  • Add: Name = SQL Server (Any meaningful name), Port Number = 1433 (by default, if you have changed the default port you have to make sure you enter the corresponding port number)

Monday, February 09, 2009

DATEDIFF Function - TSQL - Microsoft SQL Server 2000/2005

Ex: DATEDIFF(yyyy, applicant.DateOfBirth, GETDATE()) = 28 [age of applicant in years]

datepart - Abbriviation
year - yy, yyyy
quarter - qq, q
month - mm, m
dayofyear - dy, y
day - dd, d
week - wk, ww
hour - hh
minute - mi, n
second - ss, s
millisecond - ms
microsecond - mcs
nanosecond - ns

Thursday, December 11, 2008

Managed Debugging Assistants - Microst .NET Framework

Symptom:
The CLR has been unable to transition from COM context 0x1a1a90 to COM context 0x1a1c00 for 60 seconds.
The thread that owns the destination context/apartment is most likely either doing a none pumping. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.


Possible Reasions:

1. Deadlock
2. A very long operation, which worth more than 60 seconds.



Resolution:
If execution does not trap in a deadlock
It is possible to execute an very long operation by Disabling Visual Studio’s MDA (Managed Debug Assistant)
Visual Studio 2005: To disable MDA please add or edit following registry key:

1. Run > regedit
2. Navigate to > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework
3. Set [MDA=”0”]
4. Or create MDADisable.reg file and paste following text and run it

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"MDA"="0"

Please note: Always it is useful to leave MDA enable for efficient debugging. To enable MDA please set MDA=”1”


References:
Diagnosing Errors with Managed Debugging Assistants (MSDN)

Friday, September 12, 2008

Adding page specific scripts (java scripts), styles to web content pages: Microsoft ASP.NET

protected void Page_Load(object sender, EventArgs e)
{
    ///
    /// modify existing meta defined in master page 
    /// 
    HtmlMeta meta = Page.Header.FindControl("metaRedirect"as HtmlMeta;
    foreach (string metadata in MetaDataCollection)
        meta.Content += metadata;
    ///
    /// adding content specific styles into content page's header 
    /// 
    HtmlLink link = new HtmlLink();
    link.Href = "~/styles/default.css";
    link.Attributes["rel"] = "stylesheet";
    Page.Header.Controls.Add(link);
    ///
    /// adding content specific scripts into content page’s header 
    /// 
    HtmlGenericControl script = new HtmlGenericControl("script");
    script.Attributes["src"] = Page.ResolveUrl("~/scripts/default.js");
    Page.Header.Controls.Add(script);
}
public IEnumerable<string> MetaDataCollection { getset; }

Tuesday, August 26, 2008

Could not find part of the path: Microsoft ASP.NET

Symptom: When try to view the source of an .aspx or asp.net masterpage it highlight the first line (page or master) and in the little popup it says "could not find part of the path"

Resolution: clear the content of the folder
C:\Documents and Settings\{USERNAME}\Application Data\Microsoft\VisualStudio\8.0\ReflectedSchemas

Thursday, August 21, 2008

Protect file types (.xml, .doc, .html, .pdf etc.) using ASP.NET authentication: Microsoft ASP.NET

Because requests to .xml, .doc, .html, .pdf etc handled by the IIS instead of asp.net ISAPI module first it is required to configure specified extensions to be handled by the asp.net ISAPI module

How to configure custom file extension to be handled by the asp.net ISAPI module

In IIS (run ‘inetmgr’)
  1. Locate the website (or virtual directory, which configured as a web application) you want to configure custom file extensions to be secured.
  2. Right click and find the ‘Virtual Directory’ tab under properties
  3. In ‘Virtual Directory’ tab click configuration
  4. Add extension (ex: .xml) and browse aspnet_isapi.dll from the usual location (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727). If you can’t find the exact directory perform a search and locate it.
  5. Uncheck ‘check that file exist’ checkbox just in case of request to a non existing file. then press ok
  6. If it is local it is recommend to do a IIS reset (run ‘iisreset’) if not if it is the production server or UAT, recycle the application pool
For securing asp web applications: please review my previous post - ASP.NET Authentication

Tuesday, August 12, 2008

The following module was built either with optimizations enabled or without debug information: Microsoft ASP.NET

Symptom: Solution includes a web project and a class library(may be more). But can not hit any break points in class library as it says ‘no symbols has been loaded’

  • Try 'Configuration Manager' – make sure all project configurations are set to ‘debug mode’ and clean the solution
  • Try web config – make sure you have set [debug=’true’] in compilation section.
  • Remove the assembly reference and try adding it again.

Friday, August 08, 2008

Oracle replace (XML) - Oracle 10.2 E

update affiliate set config = REPLACE(config, 'old.text', 'new.text') where id ='SADB12345';

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...