a collection of technical fixes and other randon stuff

Spodworld

  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

Solving Error Unable to cast object of type '<>f__AnonymousType1`1[myType]' to type myType'.

Problem

When coding in MVC , i Came across this or similar error message:

"Unable to cast object of type '<>f__AnonymousType1`1[myType]' to type myType"

Background


I had been getting used to wrapping parameters in new{} when passing data from the controller to the view.
This error message was saying, i can't convert you class to your class. The new{} statement wrapping my object was changing it to an 'anonymous type'. So how did i fix it?

 

Solution...

 

I found that removing the new{} section of the code solved this for me.

MVC error "Cannot insert explicit value for identity column in table 'TABLE_NAME' when IDENTITY_INSERT is set to OFF."

When doing a simple MVC application, I kept coming across the error:

 

"Cannot insert explicit value for identity column in table 'TABLE_NAME' when IDENTITY_INSERT is set to OFF."

Prior to this I had created my table and generated the model/controller etc... but had made a change to the table to have an auto Id with increment of one.

Rather than re-building your model and other classes, the folllowing should help to fix it:

 

  • Edit the .edmx file of the model involved
  • Click on the primary key/index involved
  • Go to the properties window and scroll to the property [StoreGeneratedPattern] and set it to "Identity"
  • Recompile and try again

 

THis worked for me, hopefully it will help you too!

Schema Compare for Oracle error: "The given key was not present in the dictionary"

When trying to use Schema compare for Oracle, the following message appeared and comparison failed with no detailed information...

"The given key was not present in the dictionary"

 

 

 

There is not much detail on the issue , but to work around this, carefully watch the progress as the comparison is running..

Then look at the options for your project, there may be a switch to ignore the item it was last doing before it fell over.
Try this or a similar /related option, or just try a few to see if it works and narrow it down.

I found on this occasion, the 'Ignore permission' option allowed me to continue, but i would love to know which object was causing this error.

You may have similar issues on other comparison groups. Hopefully this technique will help provide a workaround if a cure is not possible.

 

For further information, you may want to try enabling verbose logging see this link on instructions....

http://documentation.red-gate.com/display/SCO3/Logging+and+log+files

 

Error 998 , Failed to retrieve error message from print engine

If you ever get this message.....

Error 998 , Failed to retrieve error message from print engine.

We found this whilst doing a crystal report that was running against an oracle database.

The cause was that a VIEW had been created for use with the report. Whilst designing the report, the queries worked, when running the report, it was being called by a different database user which didn't have permission for the report.

This was solved by granting the permission to access the table within oracle.

Hope that helps

Running a published command line executable as a Scheduled task in Windows 7

If you experience any of the following errors while trying to run a scheduled task:

  • Task Scheduler failed to start instance "{xxxxxxxx-8xxxa43-xxx-xxxx-xxxxxxxxxx}" of "myprogram"  task for user "mydomain\myuser" . Additional Data: Error Value: 2147942593.

It may be that you are using publishing in visual studio to deploy this.

How to fix it:

First of all , once published you need to run the myapp.application file for it to be installed.

Then you need to consider that this installation puts the application elsewhere. If you dont need auto updating, then teh best bet is to point your scheduled task to the installed location.

Typically this would be in...

C:\Users\myuser\AppData\Local\Apps\2.0\xxxxxxxxxxxxxxxxxxxxxxxxxx\xxxxxxxxxxxxxxxxxx

Where the user is the same as that you installed it/will be runnning it and teh xxxxxx is some random crap.

Best way to find this is to search for a file in your app from  C:\Users\myuser\AppData\Local\Apps\2.0 and then right click on the file and select 'open location'

This solution worked for me, however our solution did not require auto updating which some of you might need.

Any advice on getting the main .application file call would be great. I suspect it will permission based problems.

 

How to get past MSAccess error 'database or project contains a missing or broken reference to the file 'comdlg32.acx' version 1.2'

I came across this error message while trying to open a db/db app developed in MSAccess.
unfortunately the UI would freeze after clicking okay and i couldn't continue.

To get around this I opened the access  file/ .mdb file  in "design mode".

To do this hold down 'shift' while opening the database.

This should hopefully skip any code that has been added that stops the database from opening.

 

Hope that helps you!

VMRun reports could not connect to the virtual machine or permission denied

Problem:

Recently I was creating a c# windows service which interacted with VMware machines.

When trying to start up a VM by calling VMrun.exe  i got the error message

"Unable to connect to host"

I found this by piping the response to a text file.

This is how it was solved:

To get around this I changed the command i was using to not use the GUI (nogui) option.

The only thing you need to consider is that running VMs will not be controllable by your manual login/UI as they are running via different process.

 

Full command line details are available here:

http://www.vmware.com/pdf/vix162_vmrun_command.pdf

Robots.txt , dont forget to fill it in

Primary purpose of robots.txt file on your website is to tell search engines and crawlers what NOT to index.

One common mistake is to not fill it in correctly, this for one can cause google to think the file is invalid.

This usually happens if you think 'i dont want to block this site' so i wont put anything in it.

 

My advice when creating a robots file is to create a rule to block an imaginary folder or file.

eg:

User-agent: *
Disallow: /mynonexistantdirectory/
Disallow: /myloginpage.ashx
Sitemap: http://mywebsiteURL/sitemap.xml

(replacing mywebsiteURL with whatever your site is)

If you have things you actually need to block , then use them instead, just dont leave it blank.

Virtual Machine reverted to snapshot by it's self

Ever had a virtual machine revert to an earlier snapshop by it's self or for no apparent reason?

It happened to us today, and it was partly due to a poorly designed popup message.

In VMware there is an option to tell workstation what to do when you shut down a virtual machine.

The options are:

  • Just power off
  • Revert to snapshot
  • Take a new snapshot
  • Ask me

(see attached image)

If you have this on 'ask me' then you will get a popup message when you shut down the virtual machine.

The problem is , that the options on this pop-up have a very wide area that's sensitive to mouse clicks. The clickable area extends right over to the OK button, which if you're not careful, means that if you miss the Okay button, you select the 'revert to snapshot' option.

 

 

To prevent this from happening (and it will, usually when things are slow and not working well) set the 'Just power off' option in the settigns for each VM.

 

Hope that helps!

SQL management interface locked the database and remote logins

Today there was a problem,

The site stopped working, no one could log into the interface, remote desktop onto the server failed / didnt work.....

The problem was someone doing a backup of the database server. They had  remote desktopped into the system and started a backup, half way through an error message popped up and the system halted while SQL server waited for the response.

Every now and then something you do on MS SQL server throws up an erorr message. I'd advise to always act on it in a timely manner, as sometimes it keeps tables in the database locked whilst waiting fro a reply.

Keep focussed and dont do backups during critical times of the day Smile

 

If anyone knows why this happens, i'd love to know so do leave a comment.

Cheers!

Reducing Transaction log growth in MIcrosoft SQL server 2005 /2008

A situation that you may find yourself in when developing or managing a database with high throughput is that the transaction log tends to grow faster than you would like.

 

The easiest way out is to switch the database to use simple logging. But this might not be an option ....for instance, you may need to ensure that you can roll back data and provide full recovery ability.

The second option is to increase the frequency of your full backups and clear your transaction log out more often. This may keep youi running for a little longer, but can be lots more work.

The third option is to look at your Stored Procedure code and reduce unwanted transactions.

Transactions - good or bad

Theres really no argument to say that transactions are bad on the whole. Without them , databases would be as reliable as a Bin-man on strike. But they can be too much of a good thing on busy, data critical dataabses.

A developer will go round ensuring all essential logic is encased in a try-catch and is enclosed in  begin trans / commit trans /rollback transaction statement(s).
This can be bad if all the code is doing is a select statement.
Transactions are only needed when something gets UPDATED/DELETED/INSERTED or the database gets modified in any way.

Step 1: Remove explicitly declared transactions where theyre not needed.

Transactions where you dont expect them or didnt think.

Next, comes a more sneaky culprit. "Temporary tables". These are often added to help process some complex logic or extract data from some XML file.
The act of creating a temporary table and doing insert/update statements creates a transaction for each one.

Step 2: Look for stored procedures who should just be doing select statements and check for temporary tables. If they're being used try to remove them completely or replace them with table variables. These wont modify the dataabase structure and therefore reduce the transactions.

More transactions means less!!!?

Table variabls may not be possible for your solution, or you may not have time to rre-factor your code.

An alternative method may be to re-instate or add explicit transactions to enclose the whole stored procedure and then perform a purposefull Rollback to clear the unneccesary transactions from the log.
This esentially doesnt change your code much , but gives you control over the many unexpected additional transactions that are present in your code.

How to spot them

Use SQL profiler and add "Transaction" events to those you are monitoring. You will find your stored procedures execute but there are many additional entries without any SQL text  displayed. These are the hidden transactions that are being created.

Also use this stored procedure to help find use of temporary tables. It searches the stored procedures for some text.......

-------------------------------------------------------------------

CREATE PROCEDURE [dbo].[Find_Text_In_StoredProcedure]
@StringToSearch varchar(100)
--WITH_ENCRYPTION_REPLACE_ME_FOR_LOCAL--
AS
   SET @StringToSearch = '%' +@StringToSearch + '%'
   SELECT Distinct SO.Name
   FROM sysobjects SO (NOLOCK)
   INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID
   AND SO.Type = 'P'
   AND SC.Text LIKE @stringtosearch
   ORDER BY SO.Name

--------------------------------------------------------------------

IE hangs whilst downloading flash movie

A few weeks ago , i came across a glitch which may catch out you developers who use Firefox a lot for testing your code.

 

I recently added a ASp.net control to display youtube videos. The links came from a database and the customer hadn't got much content. As a result there were several entries that didnt have links. This worked fine in firefox, but Internet explorer hung whilst trying to download the non-existant video file. 

Remember , always test things in both browsers and use default URLS when linking to video or just display something else like a comming soon message.Laughing

 

 

Problem connecting to port 25 on windows Vista

If you're havinf problems connecting to port 25 on Windows Vista, try the following :

 

1. Try using Telnet from the command prompt.

2. If Telnet is not installed, add it from the Control panel.

3. If you can use telnet but still cannot connect, try Telnetting to port 25 on a different server.

4. If still no success, then there is probably some blocking in progress.

5. Try turning off Windows Firewall, and retry your connection.

6. Check the Applciation event log (via control panel/ admin tools) for any  suspicious events. Most likely an antivirus program cas blocked connectivity to prevent spammers.

7. Check your Antivirus settings. Mcafee Antivirus had blocked me in my case.

 

Hope that helps! :)If so, dont forget to say thanks!

SQL Management Studio Express glitch

I came across an annoying glitch in an instance SQL Management studio express today.

The install was with SQL2005 Express, and windows 2003 server. 

When i expand some child nodes eg: list of databases, i got a persistent error that would require a second retry to expand the nodes.

 The error was :

 

TITLE: Microsoft SQL Server Management Studio
------------------------------
Unable to cast COM object of type 'System.__ComObject'
to interface type
'Microsoft.VisualStudio.OLE.Interop.IServiceProvider'.
This operation failed because the QueryInterface call
on the COM component for the interface with IID
'{6D5140C1-7436-11CE-8034-00AA006009FA}'
failed due to the following error: No such interface
supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE)). (Microsoft.VisualStudio.OLE.Interop)
 
To solve this  i found registering a dll worked for me...
try entering this at a command prompt
----------------------------
regsvr32 actxprxy.dll
----------------------------
 
...wish i tried this days ago now it cut my click count in half :)