Tuesday, March 22, 2011

Just another illegal access to loading collection EXCEPTION

There are many reasons for this exception to pop up especially if you are using the Lazy initialization feature of NHibernate.

I had simple bi-directionally mapped one to many relationship (Error - Error Details). Nhibernate was not throwing any exceptions during the loading of a List of Errors, but WCF was complaining about a type mismatch when trying to serialize the list of Errors. [Note. I have reference preserving custom datacontract serializer implemented that works fine.]

This made me look into the actual list which WCF is trying to serialize, then only i noticed that the Error Details collection was full of this "illegal access...." exception.

couple of hours of googling brought me nothing as various articles suggested, setting inverse true, setting access attribute, orphaned records in the database etc. where none of these was the reason for mine, but please note that these can also be the cause for this exception so do not rule them out.

Finally mine was due to a type mis -match in the Error Details mapping, in the hbm file, so if none of the above solves your problem take a second look at you hbm file mappings that can be the culprit in your case.

Monday, March 7, 2011

Cannot open backup device 'filename'. Operating system error 5/3

This Error kept me occupied for the most of the day yesterday, as i was trying to create a job Manager which automatically backs up SQL server db(s) on a given server with SMO objects. (well yeah. :o) its not the only thing it does).

Anyways As the message says the backup operation failed. First i was getting the Message with Operating system ERROR 5. I was running the C# program with a windows account, with Full privileges to run backup jobs on the SQL server, but still the back up JOb failed. The reason behind this is that no matter what the account that i use to run the code. It uses the system account under which the SQL server service runs to perform the backup operations.

Two things, you can either give permissions to the system account to perform backup operations and full access to the backup location, or can make the service hosted under a account with sufficient backup privileges and permissions to the backup locations.
But my problems were still there and was getting the same annoying ERROR over and over, it took me almost half an hour to notice that this time the number has changed from OS error 5 to 3.

Then it was a matter of seconds for google to get me difference between codes 3 and 5. 3 was to say that it "cannot find the path specified", and 5 meant "Access Denied". There was a spelling mistake in the path given, and after fixing that it was all good. Why can they include that little piece of information in the ERROR message ??