I am trying to parse a result from a SQL Server that is returned as XML (using FOR XML
in the query).
I have an .EDMX
file that maps the stored procedure to a complex type (with one column: Name = XML_F52E2B61-18A1-11d1-B105-00805F49916B, EDMType = String, Db Type = ntext, Nullable = true, MaxLength = Max).
When I call the stored procedure the resulting type is:
ObjectResult<"ResultName">
When I try to write it out to the console I get an error message
The data reader is incompatible with the specified '"ResultName"'. A member of the type, 'XML_F52E2B61_18A1_11d1_B105_00805F49916B', does not have a corresponding column in the data reader with the same name.
So, because I was getting an error message using a complex type, I decided to try changing the result to a scalar: string.
What I get now in the Output Window (using System.Diagnostics.Debug.WriteLine("objectName")
) is:
(System.Data.Entity.Core.Objects.ObjectResult`1[System.String])
If I try to do anything with the result, I get error messages if I foreach or for over it I get an error
The specified cast from a materialized 'System.Int32' type to the 'System.String' type is not valid
What the hell does this mean? (In fact if I just do a .Count()
on the returned object I get the same error message)
So I guess my most pressing question is: how am I supposed to get a XML result from SQL Server through a stored procedure?
NOTE : I am not talking about an XML column in the database, I am talking about returning a query result as XML.
Any help would be greatly appreciated.
Thank you,
Tim
For those interested, this issues is related to the fact that I have 4 different SQL Server instances that I am dealing with (Local, Dev, Stage, Prod) and I was using the incorrect instance to get this information.
I created a stored procedure that returned XML, I added that to the Local instance and then when I was running my test application, I was looking to Dev to get the information. Since the stored procedure wasn't there, I was getting errors. Sorry for the long question that ended up being noting but a mistake on my part.
Doh.
Thanks, T
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.