Archive for December, 2009

LINQ SubmitChanges throws Index Out Of Range Error

December 23, 2009

You’ll get this if you have Associations in your dbml file which do not reflect the reality of your database.

In my case I was given a dbml file (NOT MY BUG! NOT MY BUG!) that had spurious Associations in them. Like unwanted relatives these must be bought off sent to nunneries deleted.

My database tables are:

Product
Order
Customer
Student

I was doing an update on an Order record and got the Index Out Of Range error on SubmitChanges.

Inspecting the dbml, on the advice of this very helpful thread on Stack Overflow and also this one on MSDN LINQ Project General, there were LINQ Associations between Product->Order, Product->Customer and Product->Student.

The last two Associations were spurious. They shouldn’t have been there, specifically, there is no ProductID ForeignKey on Customer and no ProductID ForeignKey on Student either

Once I deleted the spurious, unwanted, grotesque, unneeded, and overall wrong Associations I was once again able to save my Order records during Update, so making the planet safe for Capitalism.

Server Did Not Recognise The Value Of HTTP Header SOAPAction (Or How Not To Add A New WebMethod to an existing WebService)

December 17, 2009

This can come about when your Web Services References file (automatically generated by Visual Studio) is out of sync with your asmx file because you have manually hacked added some Web Methods. Make sure that all your WebMethods have corresponding entries in the Web Service Web Reference file (Reference.vb or Reference.cs).

WARNING: If you are trying to Add a new WebMethod to an existing Web Service do not do what I did below. It will only consign you to a Journey of Pain.

I am maintaining an app. that has a large WebService that operates on a group of DataSets. Each DataSet has three WebMethods associated with it. I created a new DataSet, cut and pasted the three standard Web Methods the app. needs to operate on the new DataSet and manually hacked the Reference.vb file to set up the calls to Invoke the Web Method and the Async versions of the Web Method i.e this stuff:

Public Function GetPreviewSEODataSetByDomain(ByVal domaincode As Integer) As System.Data.DataSet
Dim results() As Object = Me.Invoke(“GetPreviewSEODataSetByDomain”, New Object() {domaincode})
Return CType(results(0), System.Data.DataSet)
End Function

BUT I only manually hacked in the necessary Invokes for ONE of the WebMethods, not all three. For some reason this caused the SOAPAction error. When I removed the other two WebMethods from the asmx file the error went away.

If the above does not pertain to you, make sure you haven’t messed up the Web Service Namespace.

Now here’s what I should have done:

How To Add A New WebMethod to an existing WebService

1. Add the new Web Method to your asmx file. Decorate with WebMethod attribute of course.
2. Get Visual Studio to update the WebReference file, Reference.vb/Reeference.cs. This file does not belong to the Web Service per se. Rather it belongs to the Project which calls the WebService. Visual Studio generates it when you add the Web Reference.

To update it, locate the reference to your Web Service in your calling Project’s Web Reference folder, right-click and select Update Web Reference from the Context Menu. No more hacking, everything works, pain in cranium stops. To celebrate, I recommend making yourself a free instant coffee from the staff room. That’s what I did.

Update: Jul-23-2010
If you do the Update References thing and you don’t see your new Web Method, check the WebServices Properties by right-clicking on your Web Reference and going to ‘Properties’. Check out the URL for the Web Service and make sure it’s correct.

In my case the Properties had the URL of our PROD Web Service which didn’t help me much while I was adding a new method to the DEV Web Service. So I changed the PROD URL for the DEV URL and UpdateReference did its thing.

Cannot Drag Additional Table From Server Explorer Into Existing DataSet (.xsd) Failed to add TableAdapter.

December 8, 2009

Just a short one here,…

I have a very complicated DataSet (.xsd) file and our schema is being updated. I needed to drag a couple of new tables from the ServerExplorer into the DataSet Designer…but Visual Studio wouldn’t let me do it. I just got the ‘ghostbusters’ icon and the table would not drop.

Trying to work around the issue, I did right-click on Designer Add->TableAdapter and configured the Adapter but when clicking ‘Finish’ I got the error ‘Failed to add TableAdapter’ along with the SQL Named Pipes Provider error 40.

For half an hour I toyed with hand-coding the necessary table and all associated ADO.NET code directly into the DataSet designer file. Fortunately this madness subsided.

Then I created a new DataSet and copied/pasted the old DataSet from the Designer into the new one. This worked. No Named Pipes errors AND I was able to drag new tables into the Designer for the new DataSet. But this was all just a Journey Of Pain. I should be able to simply edit the existing DataSet. I threw a brick through the monitor and went home for a relaxing session of concreting the hamster (also here) to let my right-brain work on the problem unencumbered by reason.

Well today’s a new day and since it was my last straw, what I did was rebind the Project to Visual Source Safe. I had unbound the Project from Soure Control a little earlier for weird reasons I will keep to myself. Once I rebound the Project to Source Control via File -> Source Control -> Change Source Control I was able to add the new table to the Dataset. This was so stupidly illogical that it did not surprise me in the least.

Once day I will be able to explain why this makes any difference but today I can’t. But if you’re in a similar position why not try rebinding the Source Control? It worked for me and now I’m a multi-millionaire with a full head of hair and a tremendously loyal concrete hamster. Buy one today.

Random Thought 20-Jan-2011
Maybe rebinding the Project to Source Control make the .xsd files writable. Perhaps they had become unwritable when I unbound?