Tuesday, May 18, 2010

Dealing with browser repaints

Recently i wanted to hide a silverlight plugin content and display some html content in its place. As you might be knowing, plug-in content redrawing is a known problem all the time. So i decided to put both the contents in a table row and dynamically set the row height.



document.getElementById("Showcase").style.height = '0px';
               and
document.getElementById("Showcase").style.height = '500px';

Problem later i found that it works fine with IE, FF, Chrome but in opera its a problem. It requires you to scroll once for redrawing the content.  So you will still see the flash/Silverlight content and the new html content, untill you scroll.

This has been discussed in couple of places, but could not find any solution. So, i decided to put a scroll automatically. I tried scrolling it with 1 px, it worked!!! So i tried with 0px.... and ... it worked too!!!!

window.scroll(0, 0);
Try and let me know if it fixes your repain problem too...

Wednesday, March 24, 2010

Listing all the websites installed

Following Managed C++ code enumerates all the Websites. Useful if you are writing some kind of installer.

This requires IIS6 Metabase pack installed on IIS 7.X. Refer my other article for IIS 7 based installers.

For now...

System::String* entryName = System::String::Format(S"IIS://{0}/w3svc", computerName);
System::Text::StringBuilder* sb = new System::Text::StringBuilder(512);
System::DirectoryServices::DirectoryEntry* rootEntry = NULL;
System::DirectoryServices::DirectoryEntry* childEntry = NULL;
try
{
rootEntry = new System::DirectoryServices::DirectoryEntry(entryName);
rootEntry->RefreshCache();
System::Collections::IEnumerator* iterator = rootEntry->Children->GetEnumerator();
while(iterator->MoveNext())
{
childEntry = dynamic_cast(iterator->Current);
if(!childEntry->Name->Equals( S"AppPools", System::StringComparison::CurrentCultureIgnoreCase ))
{
if(!childEntry->Name->Equals(S"Filters", System::StringComparison::CurrentCultureIgnoreCase))
{
if(!childEntry->Name->Equals(S"Info", System::StringComparison::CurrentCultureIgnoreCase))
{
//Print childEntry->Name;
}
}
}
}
}

Friday, January 15, 2010

Deadlock!!! ..and getting out of it.

Its easy to create deadlocks in SQL, just one slip in your code and lot of load on your script makes the ideal condition for deadlock to occur.
Microsoft believes you, have lot of faith in you. So it offers tools to resolve and rescue from your coding disaster.

Say you have a deadlock, show it. Find how you can reproduce this, unless you know how to reproduce it, you will never be sure of your fix; well, like always.

First thing to do once you see a deadlock is, extract the deadlock trace data. To do so, you can set flags in SQL by running following command
dbcc traceon (1204, 3605, 1222, -1)
This flag is set only for current session of SQL server, if you restart the SQL you need to redo it. You can also set this flag as startup parameter by adding –T1222 in SQL server properties dialog.
When deadlock occurs, you can see the DB log to contain the most of the information. I have found graph drawn by the profiler as more useful than the log.

This graph you can view in profiler and you can store as XML. This XML has all the information that can give you a lead. XDL – ie XML representation of Deadlock graph has information like
1) Procedures involved
2) Line number involved in deadlock
3) Script line involved
4) Data involved
5) Victim thread, SQL terminates one process to break the deadlock
6) Mode of lock on the resource
Most of the cases this information would be sufficient to get you out of it.

Common solutions:
1) Consider rearranging the script so that you isolate all different operations like select, delete, insert and update. Make sure you have same pattern in both the scripts who are involved in deadlock. Say delete first, select next then you do a insert in both the stored procedures.
2) Un-clustered indexes adds overhead of updating indexes which require exclusive locks and if select is also running on table, then there is a possibility of deadlock. Making the clustered index can resolve the problem.
3) Run the Query analyzer and see the execution graph. You can see the pattern of two scripts running and see the overlap. This could give you fair idea on what could be going wrong, or gives the idea on possibilities.

Now you are on your own…
Posted by Picasa

Tuesday, December 1, 2009

Deploying on IIS7

Have you ever written code to deploy on IIS 6? Then this is much more easier compared to it, no more IIS base admin and confusing interfaces.

Now everything starts with IAppHostWritableAdminManager interface, from there you just have to swim through the elements using GetAdminSection method. Pass the section "system.applicationHost/sites"to get all the site elements on "MACHINE/WEBROOT/APPHOST".

This will list all sites. Select a site or create a one in the collection. Say you need to create an applicatin under default website, select the first element in collection and find all the Application. You can create one here using createelement method. Its all XML.


Lets make to some easier. If you are looking for deploying your application through code and you know how to do it through the InetMGR MMC console, its goood enuf!

Follow these simple steps and you are there.
1) Back-up your Web.Config
2) Back-up your IIS host config file, from \System32\inetsrv\config\applicationHost.Config
3) Play around!, Setup your application manually now. Set all the handler, mime, etc
4) Your web.config is now ready. Compare once and see what gets stored here
5) Now open ApplicationHost.config and locate your application there

You will find your application under say default website as




All you have to do is get the admin section for "sites" locate the id=1 create a child element named application. Set the property called path as "/Guru" abd other property ApplicationPool as "defaultAppPool".

Create a child called VirtualDirectory and set rest of the properties.

Anything else you need to do? Well you will figure out!! You can see the difference in the original app-host file and code!
Posted by Picasa

Saturday, August 8, 2009

Compare SQL Databases

If you ever come across a situation where your application behaves differently with different DBs you have and not sure if any of the Stored procedures have changed...?
Following SQL script can be used to compare the Stored procedures.
select top SYSCOM_1.text, DB2.text 
from MyDATABASE_1.dbo.syscomments SYSCOM_1 
inner join 
sysobjects so on so.id=SYSCOM_1.id inner join 
(select SYSCOM_2.text,SYSCOM_2.id, so.name from MyDATABASE_2.dbo.syscomments SYSCOM_2inner join MyDATABASE_2.dbo.sysobjects so on so.id=SYSCOM_1.id )
DB2 on so.name = DB2.name COLLATE DATABASE_DEFAULT 
where DB2.text <> SYSCOM_1.text COLLATE DATABASE_DEFAULT

Tuesday, August 4, 2009

Security update for Microsoft Visual Studio 2005

On July 28th, MS rolled out a security upgrade for MS Runtime files. If you haven't built your c++ project from last few day, you have a surprise waiting.

Welcome to the world of Manifest Hell!!!. Soon your eventviewer will be filled with SideBySide error. If you haven't rebuilt of your binaries completely, you will end up getting two entries in your binary manifest. If your test machine is not updated with latest windows updates, your application will not launch at all. You need to update have the runtime binary with newer Runtime.

So here is what you need to do if you are getting SideBySide error.

Open the manifest file(Or the Binary if you are embedding the manifest). See if it has two entries for dependency..













8.0.50727.4053 is the new version after the upgrade.

rebuild all the Dependant projects, so that all are using the newer runtime. In all cases make sure you have only one dependency, if there are more look for its dependency and rebuild'em.

Yes, its simple. Just rebuild.

Finally, Make sure you package right redistributable installer in the final installer.
Posted by Picasa

Thursday, June 25, 2009

MSP - Patching rules

If you create a new version of your program and want to be able to update existing installations either with a full install package or with a patch package, you must follow some rules. Breaking these rules will cause strange effects like previously installed features appearing as advertised after the update, or files not getting updated features not getting installed etc. If you are not following them, you can expect your MSP to lead you no where :)

Some rules small and minor updates : 

  1. Follow the rules for changing or keeping the ProductCode, ProductVersion and UpgradeCode, depending of the type of update you are creating. 
  2. Always change the package code.
  3. Do not move componentes to other features.
  4. Do not move sub features. You can add new features and sub features.
  5. You can add components to existing features. If you want to add a new feature you can synchronize the installation state of a new child feature with its parent feature by setting its Remote Installation property to "Favor Parent" and its Required property to yes.
  6. Do not change component codes.
  7. Do not change the name of the key file of a component.
  8. You can modify the contents of a component (add, remove or modify files, registry keys and shortcuts), but only if that component is not shared across features.
  9. If you remove a file or registry key from a component, you must populate the RemoveFile or RemoveRegistry table respectively to delete the orphaned resource.
  10. Do not change the name of the .msi file.

Ref: Stefan Krueger@http://www.installsite.org/pages/en/msi/updates.htm