I use Entity Framework (v4.0) to connect to SQL Azure (I have the March SDK installed) and get an InvalidOperationException when trying to query a table. The exception message is an Invalid attempt to read when no data is present. , and the stack trace clearly shows that this internally happens in EF when it tries to get the column header:
at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i) at System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i) at lambda_method(Closure , Shaper ) at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Service.LoadSettings() in C:\Service.svc.cs at SyncInvokeLoadSettings(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
This is due to the data in the column in the second table (Settings in the example below). This works fine if I query another table (e.g. Users in the example below) or exclude a query for this column. Code example:
using (var db = new DBEntities()) { var users = (from u in db.Users where u.PK == userid select u).ToList(); if (users.Any()) { var selectedUser = users.Single(); if (selectedUser.Password.Equals(passwordHash)) {
I tried to recreate tables, change table names, column names and data types, and none of them help. If the table is empty or the column contains a "small" data set, then it works, but at the moment when I have one row in which the "big" data will not work!
What I mean by small and large, well, they do not look very big and big for SQL:
- 'small' <~ 8k
- 'large'> ~ 8k
I can confirm that the problem is not related to me deleting the context before.
<h / "> Update
- This is just a read, insert works great.
- This does not happen when I use LINQ to SQL, only with EF.
- A bug reported by Microsoft as I suspect this is abnormal behavior.
Robert MacLean
source share