I have an iPad app that uses Core Data with Sqlite. I keep getting errors when a save is called on the managedobjectcontext. The error is sql error (19) constraint fails. I found a few websites that lead me to modify my generation code and update the Z_MAX field in the table Z_PRIMARYKEY table. Are there any other things that Core Data does behind the scenes similar to this?
Note: Yes, I know I shouldn't be doing this but part of the problem is the core data database is over 5 MB and it takes a long time to process the data from a plist. (Maybe JSON would be faster?)
EDIT I just noticed Z_ENT which is the entity id. I have to add that into the generation as well.
EDIT 2 Go the Entities mapped but I'm still getting the error. It is having trouble doing deletes and updates even through it appears to be valid.
Appeared to just be an issue with the app itself.
Related
Been tasked with moving a code first database from MSSQL to MySQL. After a few hours of kung fu, I was able to get the asp.net core project to properly deploy all migrations to mysql. Now I need to migrate the data inside of the existing mssql tables. I saw posts mentioning MySQL Migration Toolkit but that appears to be old. Also attempted to do so with MySQL Workbench and DBLoad's Data Loader but haven't had any luck.
Table structure is pretty simple with incremental integer keys + the usual crap with asp.net core identify framework (GUID). Just need to keep that consistent during the migration. What is the best way to migrate the data now that the table structure is setup in MySQL? Any recommendations would be greatly appreciated!
Update: Some more details...
I attempted a direct migration of the database from MSSQL to MySQL using MySQL WorkBench and DBLoader. But failed on the ASP.net Identity tables big time plus other issues. .net core api took a huge dump in multiple places so that idea is out.
From that point, I migrated the api controller over to mysql and then had to fix a myriad of issues related to mssql fks being too long and a few other issues.
So at this point, the controller works on mysql. I just need to dump all of the data into MySQL and keep the FKs consistent.
I have had a few thoughts with it such as CSV export>import and/or trying a few other things. Any recommendations?
You can use Data Export wizard built-in with SqlServer Management Studio (task -> Export Data)
or use SSIS package to migrate data.
Tried MySQL Workbench, DBLoad from DBLoad.com etc to migrate the data directly and they all failed.
So ended up finding a "solution"...
First off, I modified the ASP.net Core project with:
//services.AddDbContext<ApplicationDbContext>(options =>
// options.UseSqlServer(
// Configuration.GetConnectionString("DefaultConnection")));
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(
Configuration.GetConnectionString("DefaultConnection")));
Then went to Package Manager Console and ran: update-database
This created all of the tables in MySQL.
Then opened up Microsoft SQL Management Studio. Right clicked on the database Tasks > Generate Scripts. Saved everything to one file with Advanced option Schema and Data selected.
Then opened the db script in Notepad++ and applied the following edits using Replace with Extended Search Mode enabled:
GO -> blank
[dbo]. -> blank
[ -> blank
] -> blank
)\r\n -> );\r\n
\r\n' -> '
DateTime2 -> DATETIME
After edits were made in Notepad++, I removed all of the SET, ALTER and CREATE related stuff from the text file and then copied all of the insert lines into MySQL Workbench in order to ensure foreign keys were already populated before that table's data was inserted. Thank goodness there were no Stored Procedures to deal with! What a pain in the tucus!
Also on a side note, the app is hosted on Azure. Spent a couple of hours fighting the API not connecting to the database. This was not apparent at first as the app was fake throwing a 404 error to Postman. When I first attempted to wire up the API controllers to the MySQL DB, I entered the database connection string into Azure's App Service Configuration. It didn't work at all even though running the app locally worked fine. Ended up finding another post on this here site mentioning to get rid of the database connection string out of the App Service > Configuration window. Worked like a champ after that. All of the data with its auto incremented keys linked up without issue.
I am very pleased with the results and hope I never have to go through this process again! It is always a nice feeling to know an app now runs on a completely open source infrastructure. Hope this helps someone. Good luck.
I'm having a strange problem with ASP.NET MVC4 and Entity Framework 5: The web application I'm building retrieves data from a database and sends it as Json into a viewmodel on the page, from which it then gets presented in a table on the page. The data represents the state of some datapoints that change every now and then.
Now I observed the following behaviour:
when I run the web application from my development server, everything works fine and the shown data is up to date.
when I deploy the web app to a production server (which talks to the very same DB), the page does not represent the current state of the data
I can't breakpoint the controller method that retrieves the data, as it only occurs on the production server, but when I look into the Json data I can see that it actually is old data. So it seems like EF is caching the retrieved data. This is a serious problem as we use this web application for industrial monitoring purposes and therefore need to rely on up-to-date data.
Has anyone encountered the same issue? Any help on this is greatly appreciated!
I don't know entity framework that well but I think this has something to do with change tracking. I'd try disabling it to force EF to re-query the DB, I think (and others please can correct me if I'm wrong) but unless SaveChanges has been called on an ObjectContext if you re-query the same data the database won't be queried again.
I've used MergeOption = MergeOption.NoTracking (on the ObjectSet) to turn it off in my project.
Pls, could you help me on the following issues:
I would like to migrate from mysql to oracle. I used Oracle Sql developer. I import Mysql thirty packet but when i was start migration i get this error
ORA-04 098: trigger 'SYSTEM.MD_PROJECTS_TRG' is invalid and failed re-validation
then migration stop
Have you ever seen this post and tried this solutions?
A problem of constraint or foreign key surely?
Just so you know the Data Move operation actually performs 3 different actions in the following order:
1. Disable all constraints (FKs,PKs).
2. Move data using multiple streams so that it can migrate more than 1 table at any time.
3. Enable all constraints (FKs,PKs)
It appears that for some reason SQL Developer is failing on step 1 where it is trying to disable the constraints. Have you tried to generate the data move scripts for an off-line data migration?. You can look at the disable constraint scripts and run them manually before attempting the on-line data migration again. Hope that works.
Yes you can specify a different schema (need to use the connection for it). But you will have to use the same repository that you used for migration so that it can pick up the mappings for the source database.
For the Data move issues, you can try the followiing:
a. For moving the failed tables one by one i.e. right click on the table in the source database and choose 'copy to oracle' and then choose only data migration (append mode).
b. You can also try changing the default DATE formats for the source database in the SQL Developer to the actual one used in the source database. The default it uses is mm/dd/yyyy which may not be the right one in your environment( --> Preferences-->Migration-->Data Move options). Some times this also causes problems when migrating data
From my personal experience, SQL Developer creates a log file in an XML format under \localuser\applications... directory. So you will have to dig a bit more to find out the log file which will contain the actual error.
More informations in this link -> https://forums.oracle.com/forums/thread.jspa?threadID=2357687&tstart=90
I am using Entity Framework 4.1 and SQL Express. I have been trying to create models inside the emdx file and from that create the tables inside the a .mdf file. However, I am unable to get that work.
However, I am able to get the "Update Model from Database" to work, so there don't seem to be a problem with the connection string.
What am I doing wrong?
I tend to copy the generated SQL script and execute it myself using SQL (Enterprise manager 2008 in my case), gives you better feedback and more control.
Haven't really bothered setting it up so that it executes automatically, because EF sometimes makes mistakes in its scripting (e.g. trying to delete every FK twice. Once in the beginning, and then again before the containing table will be deleted).
Also, if you made a lot of changes or dropped some tables, sometimes the script isn't 100% compatible with deleting the existing database. I then just drop all FK's and tables (not just what the script tells me to) and then execute the script.
But that's just how I like to do it.
Hey all, I have a linq app using C# express2008 and sqlserver express 2005 (mdf file connection)
I followed the regular dml generation and vanilla datacontext. However i created a repository class to manage the Linq stuff.
In using the functions, selecting data works fine, updating data works in the app.But when i check the data in the tables, nothing has changed.Needless to say, when i close the app, also no change.
I used SQL profiler to see what was being sent to sqlserver express, nothing showed up.
What could be my issues?
Are you calling SubmitChanges() on the DataContext?
No primary key, or no column(s) in the L2S model marked as primary key member(s)..?
Ok... found 'a' soln.
1. changed (forced) default connection string from looking at a file to an instance of sql serverĀ (using database instead of file)
2. Attached file to sql server express..and renamed the db.
Ran app again and everything works. Only thing is..the dml still uses the old connection string..so any mods to tables have to be done in sqlserver.
This is just my quicky patch, anyone care to provide a more elaborate view?