Entity framework: unexpected cursor error - c#

I am using Entity Framework 6 and SQL Server. I am writing some code in a WCF service for saving data when receives a POST http request.
I have done some methods and they work well as expected. But now I'm writing another method.. in debug mode it seems like other, but when I call the saveChanges method I get this:
{"A cursor with the name 'FldCursor1' does not exist.\r\nThe statement has been terminated."}
But I don't even know what is a cursor... of course I have searched in the web, but I don't know why there is this message. Further, the name FldCursor1 isn't written in my code, I've searched it.
Do you know why this can happen?
I don't have used cursors anywhere... why this error?
If you need I can post some of my code, you have only to task. So, please let me know if you need code or if you have useful ideas for this problem.
UPDATE: when I get the error, I'm trying to add some new records in a table.

Related

SQL Server table.Script() method throwing strange exception

I have a server with a database on it that I can access through SSMS and I am an owner of. Meanwhile in C#, I create an instance of Microsoft.SqlServer.Management.Smo.Table which inherits from Microsoft.SqlServer.Management.Smo.TableViewTypeBase.
TableViewTypeBase has a method called Script(), and as you can see from the link there, the documentation isn't exactly illuminating.
Here's what I'm trying to do: I connect to the server successfully and to the database successfully. I can get a list (or something like a list, a collection maybe) of tables in the database via database.Tables. Then I grab a specific table from those Tables and I want to call that Script() method on it.
As you might already guess, this isn't code I have written but I'm here now trying to get it to work. For a lot of the tables I've done this with, there are no issues. However, with one of them, I'm getting this error:
Script failed for Table X
Googling for this leads to a lot of answers about "publications" and "subscriptions" that I don't think apply to my situation, but I'm quickly getting out of my depth. This link from MSDN says I need to update my "database compatibility level"?
Soooo of course I head on back to Google and find this link from the Microsoft Docs, and all is going well until I get to Step 5 and wouldn't you know it—that dropdown is grayed right out. No number is shown there. It looks like this:
And I'm pretty sure it's not a permissions issue because I'm an owner of that database!
So, wise ones: what do you recommend? There just aren't that many answers out there for this particular error and the documentation is basically nothing. I'm running out of ideas.

Impossible Error: Store update, insert, or delete statement affected an unexpected number of rows

I've looked at the other solutions regarding this error, but I believe my problem is different. As they do not work.
I have a Azure App Services backend. It's using ASP.NET and Entity.
For some strange reason, I'm unable to insert a new entry into one of my tables.
It's only this one table, nothing has changed on it. I understand why this error is thrown under normal circumstances, but nothing is changing by the time I save my changes.
Something as simple as this, is throwing the error:
var client = new Client() { Id = Guid.NewGuid().ToString(), CompanyID = "guid-fk-in-other-table" };
context.Clients.Add(client);
context.SaveChanges();
When I step through with the debugger, the context.Clients.Add(client); line takes really long to execute and the output window shows a bunch of unhelpful exceptions such as:
Exception thrown: 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' in EntityFramework.dll
The table schema is identical to my DataObject. I'm getting desperate and have no idea how to diagnose from here. Any help is appreciated beyond belief!
Well, after weeks of debugging, finally figured this one out.
There's row-level security implemented on this table. For some reason, Entity is unable to add a row if the current user doesn't pass the access predicate. I'm able to insert rows directly through SQL though without passing the policy, so this contributed to the confusion.
I guess Entity attempts to read the entry?
Anyway,
I then deleted the policy and things worked as they should. The reason they worked before, is because the calling app had cached credentials, satisfying the security policy. Once I cleared them, the issue came up.
There was absolutely nothing I could find in debugger exceptions that would have led me to this conclusion, an exception pointing out the security policy was at fault would have been welcome.

"Invalid attempt to read when no data is present" - why?

I'm getting the error mentioned in my subject line and I don't know why. I have an ADO.net entity and a domain service class and am doing this as I have read in tutorials and what not. Also you should bear in mind that it worked fine up until today, and so far as I know I didn't make any changes.
The database exists and the table is there as it always was. I suppose it's possible someone could have changed the table, but there are still entries (and they seem to be the same as before, but I couldn't guarantee that).
I am still connected to that source and it's not changed IP (I can remote desktop onto the server to see the SQL Server Management Studio).
If you want to ask what changes I made... not really any. I added a drop down box on my page which tells the user when database access is happening and after it finished, but then removing that still left me with this same problem so I rather think it's unrelated. I have searched Google, but none of the solutions seem to be for Silverlight.
Thanks, and I hope someone can shed some light here.

WCF Web-Service crashes after minor change to underlying database and entities

I've been bashing my head on this for quite a while and I'll really appreciate some help.
I am writing a website using ASP.NET. The Business Layer is separated into two parts: BL-Server and BL-Client. The BL-Server in actually a WCF-Service that is there to shield the Data Access Layer and the DB. The WCF-Service is connected to the DAL that in turn reads from the DB. We are using MSSQL.
Problems began after making a minor change to one of the tables of the DB (Adding a bool column to table "Responses").
Suddenly, every time i request information through the WCF-Service, i get the following exception:
"System.ServiceModel.CommunicationException was unhandled by user code
Message=The underlying connection was closed: The connection was closed unexpectedly."
This is kind of weird because the error occurs even when i request data from a different table (such as "Departments").
I've done some digging, and after setting a trace to the WCF-Service (see: http://forums.asp.net/t/1476129.aspx/1), i found out that the problem in the WCF-Service that caused it to suddenly close the connection was a buffer overflow. When trying to load the objects to the return buffer, the service throws the following exception:
"Writing an object with a recursive structure has limitations when it has large depth. Consider reducing the depth of the object."
That lead me to put a break point in the DAL method that loads the "Departments" data and examine the object that was about to be sent through the WCF-service.
Turns out the object has some loops in it. You can go through it's elements in an infinite loop, since "Departments" has some children elements that point back to him.
That seamed weird to me, so i checked the .dbml file, an walla - "Departments" has a list of entities that point to it. This, i found out, could be enabled/disabled in the link's (between the two entities, in the .dbml file) properties. The property is called "Child Property" and when enabled, ads a list of objects that have a foreign key to it to the element. (Example: if A has a FK to B. The B element will have the following member: private EntitySet<A> _A;)
At this point one might think that the solution would be to set all the "child property" for all the links between the entities to false. But that ends up with other exceptions such as:
"System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException was unhandled by user code
Message=Operation is not valid due to the current state of the object." (thrown by the entity).
Moreover, i don't want to mess with the .dbml file. I know that everything was fine before the MINOR change to the "Responses" table, and i find it hard to believe that a minor change in one table can cause so much of a mess in the entities' code.
I'm sorry for the long post, but this issue is driving me crazy, and i wanted to make sure i give all the relevant information.
Note: the application's structure is a prerequisite and i can't change it, so let's not go into that, please.
Thanks in advance,
SummerBulb
Update:
Since I'm using source control, i was able to compare the old "BusinessElements.designer.cs" and the new one. I found that the old file contains lots of code that deals with serialization. For example: [global::System.Runtime.Serialization.DataMemberAttribute(Order=1)], an attribute added to all the properties (getters and setters).
Was this code removed because of the new Boolean value? How can i get back the serialization-support code?
SOLVED!
Turns out the "Serialization mode" property was set to "none".
I set it to "Unidirectional" and now everything is fine.
If you've had the same problem and found this helpful, let me know by leaving a message.
Thanks!
Have a look at this article it might help you to find out why/when specific attributes are added (or removed)
Another thing to check is whether or not you are still using the same version of the Entity framework.

Sql Server Compact Edition concurrency / thread safety (i.e. not thread safe)

Over the last few months I have been developing an application using Entity Framework code first and sql server CE for the first time. I have found the combination of the 2 very useful, and compared to my old way of doing things (particularly ADO.NET) it allows for insanely faster dev times.
However, this morning me and some colleagues came across a problem which we have never seen in any documentation regarding SqlServer CE. It cannot handle more than one insert at once!
I was of the opinion that CE may become my database of choice until I came across this problem. The reason I discovered this was in my application I needed to make multiple requests to a web service at once, and it was introducing a bit of a bottleneck so I proceeded to use a Parallel.Invoke call to make the multiple requests.
This was all working fine untill I turned on my applications message logging service. At this point I began to get the following error when making the web requests:
A duplicate value cannot be inserted into a unique index. [ Table name = Accounts,Constraint name = PK__Accounts__0000000000000016 ]
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlServerCe.SqlCeException: A duplicate value cannot be inserted into a unique index. [ Table name = Accounts,Constraint name = PK__Accounts__0000000000000016 ]
Strange I thought. And my first recation was that it must be something to do with the DbContext, maybe the DbContext I was using was static or something else in my Repository class was static and causing the problem, but after sniffing around I was certaing it was nothing to do with my code.
I then brought it to the attention of my colleagues and after a while it was decided it must be SqlServer CE, and after us all setting up different test projects attempting to recreate the problem using threads it was recreated almost every time, and when using Sql Server Express the problem wasn't ocurring.
I just think it is a bit strange that CE cannot handle something as simple as this. I mean the problem is not only with threading - are you telling me that it cannot be used for a web application where two users may insert into a table at the same time...INSANITY!
Anyway, just wondering if anyone else has come across this late into a project like me and been shocked (and annoyed) that it works this way? Also if anyone could shed light on why it is limited in this way that would be cool.
It looks like a bug in SQL CE. See http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=641518

Categories

Resources