I am working on enhancing an application and using Microsoft .NET Core Identity for IAM in our application [Microsoft.AspNetCore.Identity.EntityFrameworkCore].
The database is Microsoft SQL Server. The database setup is pretty much standard except the "NUMERIC_ROUNDABORT" will be turned ON.
But when we start the application we are getting the below exception.
System.Data.SqlClient.SqlException:
'CREATE INDEX failed because the following SET options have incorrect settings: 'NUMERIC_ROUNDABORT'.
Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type
Working scenarios :
Scenario 1: When the "NUMERIC_ROUNDABORT" is turned OFF in server level, the application works fine and no issues.
Scenario 2: When I extract the table creation queries from the database and execute them with "NUMERIC_ROUNDABORT" turned ON, still everything works.
Scenario 3: When the "NUMERIC_ROUNDABORT" is turned OFF in server level, and started application first time (letting all the tables created by ef core) and turned ON, next time onwards app works, as the necessary tables and indexes are created already.
Non-working scenario :
When the "NUMERIC_ROUNDABORT" is turned ON in server level, and when we run the application first time, it throws an exception.
I understand the reason that it is expected to get the exception after a loss of precision occurs in an expression and when creating or changing indexes on computed columns or indexed views.
Could you please help me, can we fix this programmatically. Is that possible?
P.S: Changing in the database will not be a possible option[In my case].
Thank you all for your advice and help.
Related
I would like to deliver a C#.NET Core 6 application using EntityFrameworkCore 6 (EF6.Core) to a remote user, while the main intention of the application is to browse the entire MySQL server after authenticating the app to the MySQL server of the user for databases and tables including the records.
The app should parse and list all available databases,then the user should select any of the listed databases and then the app should list all tables inside the database including the tables schema, once a table is selected the table records should be parsed and be available for further processing.
As I know there are some solutions recommending CLI methods such as 'dotnet scaffolding' or 'dotnet migrations' that I do find them not applicable to my case since following conditions are not fulfilled.
My requirements are
(1) The user only gets the application executable and will not share the database structure and tables/schemas with the developer for integration.
(2) The user should not and will not execute the 'dotnet scaffolding' related commands on his machine to hand out the developer the schema of the database.
(3) The solution should be general and not specific since the application executable
should not change and get tweaked for the use cases
Firstly, I would like to know whether EntityFrameworkCore 6 is advanced enough to meet the requirements or not.
Secondly any minimal runnable working C# code that could show how the task should be done is really appreciated.
Please consider that I am beginner with EF and I would like to read and understand a simple minimum runnable code that can shed some light on how to solve the problem.
By the way if EF6 is unable to accomplish the requirements is there any other suggested solution available?
The purpose of Entity Framework Core is to build a code model for a known database. Thus, it is a very poor fit for your application.
Instead, just use regular ADO.NET methods with a library such as MySqlConnector. You can use the DbConnection.GetSchema method to get a list of all schemas and tables (that your MySQL user account has permission to view).
using var connection = new MySqlConnection("Server=...;User=...");
connection.Open();
var databases = connection.GetSchema("DATABASES");
var tables = connection.GetSchema("TABLES");
// process the two DataTables retrieved above...
I'm building an application that will use a large database that's currently hosted on Azure SQL. I also want to use ASP.net Identity. Additionally, my local machine cannot connect to the Azure SQL database due to security restrictions (I can't remove these, they are corporate IT policies).
When developing, do either of the following make sense? Or is there another option that I'm unaware of?
Add the fields from the large database, and maybe a few rows of sample data, to my localdb that's being used by default by Visual Studio? If I do this, how do I migrate over to the existing Azure database when it's time to go live?
Host the development application on Azure. This wouldn't be ideal, given that I'd need to upload the application with every change.
You could do that for small scale testing and demonstration purposes yes. Essentially to interact with the database in ASP you create an instance of the database with the reference link to the local one. Providing they are identical, you could simply just change the link to the company database when it’s time to go live. You should be careful however as working with relatively small datasets means everything will run relatively smoothly and quickly but if your coding is sloppy, it could slow the entire thing down with big data sets.
As for developing, I would personally develop on a small scale yourself locally until you’re happy with the result. However, before you do a full scale launch, I would do a pilot launch in a small section to highlight any bugs you may have pushed and halt this on azure. Then after you’ve ruled out the obvious bugs, you’ve got a much safer launch.
to work in an develop-release separated environment:
you need a intranet copy of remote database first, then use code first approach to continue working,
reverse your database to code-first:
https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db
https://cmatskas.com/scaffolding-dbcontext-and-models-with-entityframework-core-2-0-and-the-cli/
https://wildermuth.com/2017/12/20/Reverse-Engineering-Existing-Databases-in-Entity-Framework-Core-2
Enable database migrate: https://msdn.microsoft.com/en-us/library/dn579398(v=vs.113).aspx
Add identity framework to intranet database with code first: https://learn.microsoft.com/en-us/aspnet/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project
carefully maintenance migration code in later tasks, remote database will be auto-updated after your code is released
I have a strange issue, I deployed my application to production. Application is working fine. I have uploaded database too with some local data. After one day, database ID are incremented by 10000. I don't know why and how. See below picture. Blue ones are from local environment and yellow ones are of production.
Moreover when I connect to the production server and try to open any tables for edit I get an error:
This backend version is not supported to design database diagrams or tables. (MS Visual Database Tools)
If this increment some how connected to this ?
It seems Microsoft considers this a "feature" and not a bug. According to the site I found explaining it, SQL Server will do this when the server is restarted (perhaps to prevent duplicate IDs?) and the amount of the increment depends on the data type of the column, so an INT field will jump by 1,000 and a BIGINT will jump by 10,000.
Read here for more information, but essentially if you care about the value of your identity column than don't use an identity column and instead create a sequence of numbers.
http://www.codeproject.com/Tips/668042/SQL-Server-2012-Auto-Identity-Column-Value-Jump-Is
SQL Server 2012 has a new identity implementation that is shared with SEQUENCE. This unfortunate behavior is intentional.
Enable trace flag 272 on startup.
Use trace flag 272. This will cause a log record to be
generated for each generated identity value. The performance of
identity generation may be impacted by turning on this trace flag. •
Use a sequence generator with the NO CACHE
setting(http://msdn.microsoft.com/en-us/library/ff878091.aspx) o This
will cause a log record to be generated for each generated sequence
value. Note that the performance of sequence value generation may be
impacted by using NO CACHE.
Don't rely on identity values to be consecutive. Still, these large jumps are annoying im many small ways.
The problem I'm trying to solve:
I have a dev SQL Server database which is mainly used for staging data entry (occasionally it's getting extra table) and when the person using the system (MVC web app) is happy with the data entry made that doesn't break the system can by single click of a button sync that data with live version of the db on different SQL Server. This avoid getting a developer to do the job every time using RedGate SQL Compare application or similar.
The solution that seems to be the right one is using Sync Framework. I'm trying to create a separate Console App that will connect to the databases and exchange the data but this is where I'm getting lost.
So the first question is: is there any simpler approach?
Second question: if I'll continue with this approach and create provisioning processes in the DB does this means it's one way solution?
Third question: any better tutorials than this http://msdn.microsoft.com/en-us/library/ff928700.aspx because I can't get this to work on two remote servers?
I have searched for ages but only got confused even more.
I'll appreciate every suggestion. Thanks.
Yes, there is a simpler approach. Have all the data in one database. Then add an extra column to your tables indicating the status of the rows. Have the status as "temporary" or "confirmed" or something to that effect. Only "confirmed" rows should be considered the real data.
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