Problem uploading large files in ASP.NET

12. October 2012 10:35 by Mrojas in ASP.NET, C#, Cloud, General, HTML5, SQL Server, VB6 Migration  //  Tags: , , , ,   //   Comments (0)

If you try to upload large files you might get an exception like

HttpException: Maximum request lenght exceeded.

This problem occurs because the default value for the maxRequestLength parameter in the section 

of the machine.config or Web.config file is 4096 (4M).

So any file with a size bigger will fail.

However I think that the max size that you can write here is 2G 2097151

Some info can be found here:;EN-US;295626


So to change that for 512mb use something like:




        <httpRuntime maxRequestLength="524288" /> 



Crystal Reports in Windows Azure

10. October 2012 08:52 by Mrojas in Crystal Reports, Printing, SQL Server, VB6 Migration, Visual Studio, WinForms  //  Tags:   //   Comments (0)

If you ever wonder, if Crystal Reports can be used on the cloud in Windows Azure, well the answer is you can.

These two links provides some guidance on this matter: (this one is in English) (this one is in Spanish but Bing and Google Translate do a nice work here ;) )

Use Crystal Reports in VS2010

10. October 2012 08:28 by Mrojas in Crystal Reports  //  Tags: , , ,   //   Comments (0)

Crystal Reports was a tool very used by VB6 developers.

Sometimes when you are migrating a VB6 applications, you find a lot of reports created with this tool.

What should you do? Should you rewrite them on another technology?

Well that really depends on project requirements, but Crystal Reports has good support for VS2010, both for 32 and 64 bit environments.

So you don't need to throw away your reports you can still use Crystal Reports.

However that hard thing to do is where to find Crystal Reports for VS. Do you need to buy some software for that?

I have found that you can download Crystal Reports for VS2010 is just that the links are a little hidden. My friend Victor send me the following information which has been very useful for this task:



a) For Deployment Environment:
1. Download the Redistributable Package for Visual Studio  according to the platform (32 bits or 64 bits).  And install it. You will find the installer in the following link:
2. Give access to the user executing the IIS process to the path for the Temp Folder (C:\Windows\Temp or the corresponding folder on windows installation).
3. Download the "Microsoft SQL Server 2008 Feature Pack", where you can find the "Microsoft SQL Server 2008 Native Client ". Download the corresponding installer according to the platform of the server (x86, x64 or IA64).
b) For Development environment:
1. Download the "Complete Package" for development on Visual Studio 2010. Please be sure that if you're on a 64 bits machine, you check the "Install 64 bits Runtime" before you click on finish when you complete the installation.
2. Be sure that the current user running on your machine has access to the Temp Folder (C:\Windows\Temp or the corresponding folder on windows installation)
3. If you don't have the Microsoft SQL Server 2008 Native Client Provider (sqlncli10),  download the "Microsoft SQL Server 2008 Feature Pack", where you can find the "Microsoft SQL Server 2008 Native Client ". Download the corresponding installer according to the platform of the server (x86, x64 or IA64).
4. To create a new report please be sure you use a "OLE DB (ADO)" Connection and that you're using the "SQL Server Native Client 10.0" Provider, and use the right login information. If the report was previously created with a different provider, please change it on the "Set Datasource Location", editing the Provider field.

Office Interop and Call was rejected by callee

28. September 2012 13:14 by Mrojas in ActiveX, C#, Memory, VB6 Migration, WinForms  //  Tags: , ,   //   Comments (0)

This issue is mostly cause by timing issues when calling a multi-threaded app.

Some workarounds:


1. Set the application visible property to false. For example if using Word make word visible property false at the start of the method and set it back to true at the end.

This will delay some GUI changes avoiding timing issues.


2. Insert some Thread.Sleep calls (yes this is ugly)


3. Register and IOleMessageFilter. I have copied an implementation from the MSDN


Just copy this class in your code.

At the start of the method call 


            // This registers the IOleMessageFilter to handle any threading 
            // errors.


And at the end


public class MessageFilter : IOleMessageFilter

        // Class containing the IOleMessageFilter
        // thread error-handling functions.

        // Start the filter.
        public static void Register()
            IOleMessageFilter newFilter = new MessageFilter(); 
            IOleMessageFilter oldFilter = null; 
            CoRegisterMessageFilter(newFilter, out oldFilter);

        // Done with the filter, close it.
        public static void Revoke()
            IOleMessageFilter oldFilter = null; 
            CoRegisterMessageFilter(null, out oldFilter);

        // IOleMessageFilter functions.
        // Handle incoming thread requests.
        int IOleMessageFilter.HandleInComingCall(int dwCallType, 
        System.IntPtr hTaskCaller, int dwTickCount, System.IntPtr lpInterfaceInfo) 

            //Return the flag SERVERCALL_ISHANDLED.
            return 0;

        // Thread call was rejected, so try again.
        int IOleMessageFilter.RetryRejectedCall(System.IntPtr 
        hTaskCallee, int dwTickCount, int dwRejectType)

            if (dwRejectType == 2)
            // flag = SERVERCALL_RETRYLATER.
                // Retry the thread call immediately if return >=0 & 
                // <100.
                return 99;
            // Too busy; cancel call.
            return -1;

        int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee, 
        int dwTickCount, int dwPendingType)
            //Return the flag PENDINGMSG_WAITDEFPROCESS.
            return 2; 

        // Implement the IOleMessageFilter interface.
        private static extern int 
          CoRegisterMessageFilter(IOleMessageFilter newFilter, out 
          IOleMessageFilter oldFilter);

    [ComImport(), Guid("00000016-0000-0000-C000-000000000046"), 
    interface IOleMessageFilter 
        int HandleInComingCall( 
        int dwCallType, 
        IntPtr hTaskCaller, 
        int dwTickCount, 
        IntPtr lpInterfaceInfo);

        int RetryRejectedCall( 
        IntPtr hTaskCallee, 
        int dwTickCount,
        int dwRejectType);

        int MessagePending( 
            IntPtr hTaskCallee, 
            int dwTickCount,
            int dwPendingType);


<label> ignoring width styling

27. September 2012 23:52 by Mrojas in   //  Tags: ,   //   Comments (0)
label {
    display: block;
    float: left;
    width: 150px;

Problem with Windows Service that connect to Oracle

25. September 2012 13:38 by Mrojas in Access, Oracle  //  Tags: , , , ,   //   Comments (0)

Today Joseph was creating a windows service, which had an schedule task to execute something on an Oracle Server.

Everything worked out of the Windows Service but as soon as he added it to the Windows Service, it fail.

He suspected it had something to do with the 64 bit platform so he made sure to compile for AnyCPU, but it did not work...

Answer: It was the OracleClient fault. The OracleClient for ADO.NET do not work for AnyCPU. You need to use the 64 or 32 bit version.


IE Compatibility issues

21. September 2012 20:42 by Mrojas in General, HTML5  //  Tags: , ,   //   Comments (0)

It happen to me that I had a website working perfectly in my IIS and when I went to publish it it looked completely distortionated.

Why !! The eternal why.

I ended finding that it had something to do with the compatibility mode of IE, but why was it changing. It looks like it has some relation with the IIS version. Not sure why.

But the fix is to do something like:

    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <httpProtocol>       <customHeaders>         <add name="X-UA-Compatible" value="IE=edge" />       </customHeaders>     </httpProtocol>
This meta tag instructs the IE to set the compatibility mode to the highest value. 
You can use other values as IE7 or IE8So just put that and your site will look nice again :)



GetUserDefaultLCID in .NET with no API calls

13. September 2012 09:43 by Mrojas in C#, Portable  //  Tags: , ,   //   Comments (0)

I was looking for a pure .NET equivalent of the Windows API function

GetUserDefaultLCID because I want my code to be free of pinvoke references

to avoid posible issues in 64 bits.


However after a lot of digging I found that there is not direct equivalent.

You could use Thread.CurrentThread.CurrentCulture.LCID but it is not exactly the same.

So I found this great post in stackoverflow:




For some background information have a look here:


So it seems this problem manifests itself on Vista as well as Windows 7. It occurs because Microsoft seems to be in the process of deprecating the Locale ID in favor of the Locale Name.


To summarize: The relevant API calls all operate on registry values that can be found at HKCU\Control Panel\International. The value "Locale" is maintained for backward compatibility reasons and under normal circumstances is kept in synch with its newer counterpart called "LocaleName". This synch process however doesn't work under some circumstances.


Anyway, the GetThreadLocale API call gets its return value from the "Locale" registry entry mentioned above, while the others (GetUserDefaultLCID, GetSystemDefaultLCID, etc) use the "LocaleName" registry entry.


Hence the confusion.


BTW, the solution mentioned by JP in a previous post should probably be extended to





because (if i'm reading it correctly!) according to the docco the GetUserDefaultLCID call will account for user customizations.


After a bit more research, Vista is not affected at all. I've got some more detail too ...


The relevant API calls all operate on registry values that can be found at HKCU\Control Panel\International. The value " Locale " is maintained for backward compatibility reasons and under normal circumstances is kept in synch with its newer counterpart called " LocaleName ". Under Windows 7 at least, this synch process however doesn't work where processes are being run as another user (i.e. RunAs or Impersonation). This seems to be the case during installation, where the installer is launched from an existing windows session. It does however seem to work correctly if you've booted from the install CD.


GetThreadLocale gets its value from Thread Information Block or Thread Environment Block (TIB or TEB) See: For both Vista and Windows 7, the TIB is initialised with the HKCU\Control Panel\International\Locale registry entry at logon. This becomes the default Locale for all threads created during the session. Changing this registry value during a session has no effect on the value returned by the GetThreadLocale API call. The user must log out and log in again to see a change. This is the API call that Delphi uses as the basis to initialize all its locale format strings ( See SysUtils.GetFormatSettings method), from which all date fields are formatted.


GetUserDefaultLCID: in Vista, bases its return value on the HKCU\Control Panel\International\Locale registry entry. In Windows 7, bases its return value on the HKCU\Control Panel\International\LocaleName registry entry. The respective registry entry can be changed during a session and the result is immediately reflected in this API call return value.


SetThreadLocale updates the TIB to reflect the locale provided in the parameter to this call. Note that this only ever effects the thread the API call is executed from. The API calls SetThreadLocale(LOCALE_USER_DEFAULT) and SetThreadLocale(GetUserDefaultLCID) are functionally equivalent. They both derive the source locale as described in the GetUserDefaultLCID API call above."


With that information you could create a function to get that value from the Registry using just .NET framework calls. I do not love that approach either but at least is another alternative

CommandBarControl Click Event is not Working!!!!

2. September 2012 00:15 by Mrojas in Visual Studio  //  Tags: , , , , ,   //   Comments (0)

Today I was doing a VS extention as part of my weekend relaxation activities ;)

Everything was great until succendly something was not happening as I expected.

 I was adding a context menu to the code window with a dynamic list of options.

And each option had a different click delegate, but my click events were

disrespectfully discarted.

 Luckily I found this post:

 And now for a tricky part: since you ge\t your instance of CommandBarEvents inside the scope of a method, when the method ends, the Garbage Collector collects it, leaving all the event handlers orphaned. Unless you keep your instance safe from the jaws of the mighty Garbage Collector, your buttons will not respond to clicks.

To do so, just keep your CommandBarEvents instance(s) as member fields of your class. Once your class is disposed, they will be disposed as well.

 Thanks Rauchy you saved my day! (And my wife is happy because I'm finally getting out of the bathroom :P)

SQL SERVER Find and Kill User Session

31. August 2012 13:09 by Mrojas in SQL Server  //  Tags: , ,   //   Comments (0)

I found this excellent post from Aasim adbullah

        name AS database_name,
FROM    sys.dm_exec_sessions
        LEFT OUTER JOIN sys.dm_tran_locks ON sys.dm_exec_sessions.session_id = sys.dm_tran_locks.request_session_id
        INNER JOIN sys.databases ON sys.dm_tran_locks.resource_database_id = sys.databases.database_id
WHERE   resource_type <> 'DATABASE'
--AND name ='YourDatabaseNameHere'
To find out sessions which acquired EXCLUSIVE locks, modify above mentioned query as follow
        name AS database_name,
FROM    sys.dm_exec_sessions
        LEFT OUTER JOIN sys.dm_tran_locks ON sys.dm_exec_sessions.session_id = sys.dm_tran_locks.request_session_id
        INNER JOIN sys.databases ON sys.dm_tran_locks.resource_database_id = sys.databases.database_id
WHERE   resource_type <> 'DATABASE'
AND request_mode LIKE '%X%'
--AND name ='YourDatabaseNameHere'