Everything was working fine in my ASP.Net MVC5 EF6 project until I had database issues. The only way I found to resolve them was by deleting my database and migrations folder. I recreated everything from scratch and it fixed every issues I had locally (localhost).
Then I tried to publish my web app to Azure and now I get this error every time I try to Login in my App (first time my context is used):
There is already an object named 'Companies' in the database.
I searched for hours on the internet about this and found nothing about this bug when it only happens when the database and web app is published (because it working perfectly fine on Debug locally).
I have read plenty of theories about migrations being messed up so I deleted my sql databse AND my Web App on my Azure portal and created new ones. Even after this, I am still getting the error.
So it seems I have an issue in my code and I know EF6 is trying to create this database table a second time but I found no places in the code where it could do that (even less where it only happens when published). I must also tell you that nothing changed in the WebConfig and in my DbContext. Only my models changed and my Migrations folder.
I am definetly missing something here and I would really like some help to understand EF6 better. I am new to this technology and I find it very useful when it's working but when you have bug, it becomes very very painful though.
Related
I developed a simple API using .Net core and it locally works as intended. After deployment only the WeatherForecast endpoint is working and the rest results in status 500. I have used code first with EF and enabled migrations during the publish process through VS code.
Any suggestion?
Azure gives me these errors but I am not really familiar with Azure
image 1
my code
endpoint
EDIT: The endpoints are working now, but as I said in a comment below I changed my local db connection string (see my appsettings.json in git) by the one that azure gives me and everything is working correctly but, if you have alredy filled you db with many records probably that's not the entire solution
Looking into your code, I see that you have added connection string of the localdb. Did you update this in configuration on app service?
I am pretty sure that your application is unable to connect to the database and hence the 500 : internal server error
Also you should add appsettings to .gitignore so that it is not pushed to a remote public repository.
I'm having an issue with deploying a WebApp / API to Azure.
When I run it locally on localhost:44385//api/user/getuser/1, it returns the JSON for that user,
once deployed to an App Service on Azure, it starts returning a 404.
Its running on the free version as its for a uni assignment.
I've spent hours poking around and reading, and cant seem to find where i've gone wrong in the setup.
Hoping someone might of had a similar issue.
Have you checked to make sure the server's routing rules are correct and that it's not looking in the directory structure?
https://learn.microsoft.com/en-us/azure/application-gateway/url-route-overview#:~:text=In%20this%20article&text=URL%20Path%20Based%20Routing%20allows,to%20different%20backend%20server%20pools.
Please verify below points:
That the Connection String of DB is correctly picked up by your Web API/it's correctly setup and configured.
If the DB and table/collection is present when you query and if not then you are creating it through your code.
If your data is present at the right place (User with ID = 1 in DB and collection/table you are querying).
If your code is not throwing 404 incorrectly (even in positive scenarios).
I've been practicing on MVC programming and now I've reached a place to deploy my web application.
I've tried deploying on local IIS and the only error I found was because of my localDB (probably connection string, that I don't really know what to do about it)
I'd like to know how to edit the connection string and my database for deployment,
and by the way, to know if it's possible to deploy web application with more than one DB migration configs or not? if yes, how? (what should be considered while deploying?
Here I found the best solution for my problem.
by
Anthony Chu
Multiple DB Contexts in the Same DB and Application in EF 6 and Code First Migrations
I am having issues deploying my app to godaddy hosting using EF code first. I dont want my app to create the database since the database already exists.
So I read some posts on here and placed this in the constructure:
Database.SetInitializer<myContext>(null);
Now I get a permission error writing to the temp file.
Anyone had a successful experience deploying this to godaddy shared hosting?
When the project used Model first and edmx files it was deployed fine.
I was able to get this to work right after posting this..
All I had to do was move:
Database.SetInitializer<myContext>(null);
to the global.asax Application_Start
Can you post what's the server error you are receiving.
setting db initializer to null should work fine. I have tried that. If you post the exception, we can probably find out why exactly that happening
You should use a generated database from the development and remove the database initializer from your code. From my experience, I always got a problem if I didn't remove the database initializer.
I've faced kind of problem before. I am using a different hosting site though. I deployed my MVC 3 Code First app back then. When I deployed the app, I didn't remove the database initializer, so the app drop the database and try to create it again. But when it create the database, it got a permission error. The problem is, the database is actually dropped in the server but in the hosting site cpanel, it is still exist. I send a ticket to the support, and problem solved.
As per the suggestions in my last post, I installed all the Oracle providers in the database (by running all the sql files). I am trying to figure out how to tweak the default ASP.NET MVC2 sample (the one that gets created on a new project in VS) to use Oracle database. But I could not still figure out how to use OracleMembershipProvider instead of default membership provider.
P.S I installed the ODAC (Universal Installer version) and I could access the database from a simple ASP.NET application.
EDIT: I tried to add in section of , but am getting a configuration error:
It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level.
This link provides some information on the allowDefinition error. There are also a number of SO posts that describe this error. You may want to look at them as well and see what worked for those folks.