Code Project

Link Unit

Wednesday, February 03, 2010

When caching is enabled for the XmlDataSource that is control tree it requires a UniqueID that is unique throughout the application

We were using XmlDataSource in code behind and assigning the same to a menu.
XmlDataSource XmlMenu = new XmlDataSource();
This was resulting in "When caching is enabled for the XmlDataSource that is control tree it requires a UniqueID that is unique throughout the application" - Use an ID for XmlDataSource .
The solution for which is specifying the ID of XmlDataSource .
XmlMenu.ID = "Menu1";
Reason:XmlDataSource class internally calls a private method called CreateCacheKey.Now, if you are using XmlDataSource without an ID in Code-Behind. This might throw an exception - "When caching is enabled for the XmlDataSource that is not in the pages control tree it requires a UniqueID that is unique throughout the application." This is due to the absence of the UniqueID ,which is used as part of the caching key.Without ID all instances would try to use same caching key. Setting a distinct ID will resolve the problem.

Monday, February 01, 2010

Change default language from VB to VC#

Visual Studio 2005 is installed on all of our development PCs.Initially our projects were in VB so while installing we choselanguage "Visual Basic" instead of "Visual C#.Now .We are working more on C# and when a new project/site is to be created, we should take care which language we chose otherwise it will get created in default language which is VB in our case.So we wanted to have VC# as our default lanaguage. Searched google/newsgroups to figure out solution.

Solution
#1. We can do this by using Registry by changing this registry key:HKCU\Software\Microsoft\VisualStudio\8.0\General\NewProjectDialogPreferredLanguage. It was VB in our case we can change it to VC#. The same key also exist in HKEY_USERS. We might do a search for that value name and just change to VC# anywhere you find it.Though this option is not preferrable.

#2 If we wish to remove VB and use only C# in our programming environment then we could do that using add/remove programs and click on change button for the installation. Just uncheck vb and check off C#.Though this option is also not preferrable.

#3 The easiest option to do so is
a) Choose Tools -> Import and Export Settings...
b) Select Reset All Settings and click Next
c) Select whether you would like to save the current settings and click Next
d) Select the settings you want to use(change the language to VC#) and click Finish

Hope it helps the visitor.

Friday, January 29, 2010

Exception Details: System.Runtime.InteropServices.COMException: Access is Denied

"Access Denied" : Error was creeping when we are tring to load the crystal report file by using Load("~/Reports/MyReport.rpt"); The error looks silly as it is not pointing where the access should be given. After doing bit of googling and applying/reverting the changes found the solution.
Reason & Solution
When a CR[Crystal Report] is being created in ASP.NET, the .NET will create a report file in a temp folder, e.g. C:\Documents and Settings\MachineName\ASPNET\Local Settings\Temp.
#1 You can try to give ASPNET permission for this folder.
#2 You can also update web.config to impersonate.

<authentication mode="Windows">
<identity impersonate="true"
userName="mydomainname\myusername"
password="mypassword" />

I preferred the #1 solution ,as it is easier to give permissions once on the folder; You may like to try option #2 but keep a note that whenever Domain[very rare],user or password changes at that point web.config needs to be updated.

Hope it helps

Monday, January 25, 2010

TNS-3505 Failed to resolve name

On the primary database the current tnsnames.ora config for the db in
question looks like this :

LIVE =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = A.B.C.D)(PORT = 1521))
)
(CONNECT_DATA =
(SID = live)
)
)

This works ok - tnsping etc ...

now when I try to add an entry for <dbname>_PRIMARY or
<dbname>_STANDBY,

LIVE2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = X.Y.C.D)(PORT = 1521))
)
(CONNECT_DATA =
(SID = live)
)
)

I get a TNS-3505 Failed to resolve name.
I tried various combinations but none worked.

Solution:
After doing lot of comparsion with existing files TNSNAME.ORA , it appeared that nothing is wrong.
Giving the new entry a closer look revealed that minor difference ,a leading whitespace[space on left] exist . Removed that extra space , all worked fine.

Hope it helps

Tuesday, December 22, 2009

Bad Request (Invalid Hostname)

While trying to host a site on IIS /windows 2003 devleoped in ASP, we got the following error.
"Http Error 404 - Bad Request (Invalid Hostname)" .
Located the file C:\WINNT\system32\LogFiles\HTTPERR.log to see if the error could be diagnosed with error description. All the other websites were running fine.

Solution: In Web Site Advanced property Host Header value was specified. Removing the "Host Header Value" resulted in operating site.

refer the image as shown below

Wednesday, December 16, 2009

Windows 2003 /DC : Application Server Unavailable


While we were hosting an web application on IIS ,got this error
Application Server Unavailable
The web application you are attempting to access on this web server is currently unavailable.Please hit the "Refresh" button in your web browser to retry your request.

On inspecting further the event log has captured following
aspnet_wp.exe could not be launched because the username and/or password supplied in the processModel section of the config file are invalid.aspnet_wp.exe could not be started.HRESULT for the failure: 80004005

Explaination:
By default, ASP.NET runs its worker process (Aspnet_wp.exe) with a weak account (the local machine account, which is named ASPNET) to provide a more secure environment. On a domain controller or on a backup domain controller, all user accounts are domain accounts and are not local machine accounts. Therefore, Aspnet_wp.exe fails to start because it cannot find a local account named "localmachinename\ASPNET". To provide a valid user account on the domain controller, you must specify an explicit account in the section of the Machine.config file, or you must use the SYSTEM account.

To work around this problem, use one of the following methods:


  • Create a weak account that has the correct permissions, and then configure the section of the Machine.config file to use that account.
  • Set the userName attribute to SYSTEM in the section of the Machine.config file.
  • Configure the section of the Machine.config file to use an administrator account.

One other special value for userName is System, with the password AutoGenerate, which runs the process as an administrative account and allows all ASP.NET user code running under the process to have full administrative privileges.
For deployment on local development environment one can use 2nd option , for deployment on client side 1st option is the best.

System.InvalidOperationException: The control with ID requires a ScriptManager on the page. The ScriptManager must appear before any controls that

System.InvalidOperationException: The control with ID requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

We faced this error while working on one of our project's page. The error appear to be very silly as Scriptmanager was declared on the page; page worked fine on it's first load. After postback,it was giving the above error. On inspecting the page further it was found the culprit was "Page.Items.Clear()" . It was clearing all objects including Scriptmanager from Page's object list.
Rule of Thumb : donot use "Page.Items.Clear()" when using Ajax