While this wpf project runs very stabil for the past 2 years, i now get a EF problem stating "CREATE DATABASE permission denied in database 'master'."
All the migrations are in the _MigrationHistory table:
and nothing has changed from the config.
The app.config:
<connectionStrings>
<add name="DataContext" providerName="System.Data.SqlClient" connectionString="Server=********.com;Database=******;Integrated Security=False;Initial Catalog=*******;User ID=*******;Password=********" />
</connectionStrings>
the last action was a publish to a click once folder online.
I allready reinstalled EF 6.1.3 => no success
Please help we with debugging this issue, i don't know where to look first...
a simple get-migrations doesn't see the migrations.
PM> Get-Migrations
Retrieving migrations that have been applied to the target database.
No migrations have been applied to the target database.
PM>
Related
I'm trying to update the database with migration using Rider JetBrains, but when I try to "add migration" it gives me an error in the console. I believe this error is happening because my XML is causing this error because in case I don't change it to use my database connection string, the "add migration" works successfully (my database is MySQL).
App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add Server="127.0.0.1" Port="3306" Database="smartparking" Uid="root"
Pwd="1234567"></add>
</connectionStrings>
</configuration>
My server
My database
You can also use a jetbrains plugin made for handling migrations
https://plugins.jetbrains.com/plugin/17026--net-ef-migration-facilitator/
Also or :
Adding package references
The first thing to do would be adding package references. There are a few packages we’ll be needing, the first four are typically already installed when working with Entity Framework Core:
Microsoft.EntityFrameworkCore – the Entity Framework Core framework
Microsoft.EntityFrameworkCore.SqlServer – the SQL Server database
driver (other databases are supported as well)
Microsoft.EntityFrameworkCore.Design – the Entity Framework Core
design tooling
Microsoft.EntityFrameworkCore.SqlServer.Design – SQL Server-specific
tooling
Microsoft.EntityFrameworkCore.Tools.DotNet – the cross-platform
command line tools we are interested in
this link is helpful for you :
https://blog.jetbrains.com/dotnet/2017/08/09/running-entity-framework-core-commands-rider/
EDIT :
The sample of connection string :
<add name="ConnectionStringName"
providerName="System.Data.SqlClient"
connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True" />
Visual Studio 2019, C#
I'm working on my first code first implementation.
I built out a data access layer which works great. I then went to add/test out a data migration.
I created a migration file then went to the package manager console and ran this:
update-database
after a long pause I saw a message that stated:
Target database is: 'OMDB' (DataSource: (localdb)\mssqllocaldb, Provider: System.Data.SqlClient, Origin: Convention).
OMDB is my model. However, I'm not pointing it to localDB in my app.config, I'm pointing to sqlexpress:
….
<connectionStrings>
<add name="OMDB" connectionString="data source=.\SQLEXPRESS;initial catalog=MyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value ="data source=.\SQLEXPRESS;initial catalog=MyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
…
In order to get the data access layer built out, I had to add an override to the class constructor to load the connection string:
public OMDB(string szConnectionString) : base(szConnectionString)
{ }
But I don't think that has anything to do with my issue...
I have the default project set to the data access layer project (DAL), I also tried forcing that on the update-database line:
update-database -Verbose -ProjectName DAL
I did a global search for localDB in my solution and it came up with no hits so I have no idea where it's getting the idea of it using the localdb for the source...?
Any suggestions on where it's pulling up the localDB for this connection?
I managed to fix the issue by following steps.
Set your website project(where the web.config has the connectionStrings) as Default/Startup project in Visual Studio
Make sure the connectionString points to the actual db instance
Run Enable-Migrations or Enable-Migrations -Force in Package Manager Console depending on your need
You should get a message like below upon successful creation of the InitialModel:
Detected database created with a database initializer. Scaffolded
migration '202102050903200_InitialCreate' corresponding to existing
database. To use an automatic migration instead, delete the Migrations
folder and re-run Enable-Migrations specifying the
-EnableAutomaticMigrations parameter.
Ok, this one really made me burn some time.... I figured out what was causing it and also a workaround at least for now.
I have a project in the solution which is my data access layer. Even though I had that project selected in the package manager console, it created a blank app config at the top level. Since that app.config did not have the connection string tags in it, it was defaulting to localdb and eventually erroring out.
So to get around that, I copied the connection string from the data access library project app.config to the master project app.config and everything started working. Not sure why it wanted to go to the main project file but it was... I'll have to come back to this later but it's working for now.
I was following the tutorial on creating the Code First Entity Framework model on Asp.NET MVC Application from this tutorial.
As I proceeded, a file with the .mdf extension should have been generated under the App_Data folder in my project (in the solution explorer section). Currently this folder is empty.
I have tried building the project and cleaning it. Moreover I have enabled Show All Files option in the folder. I even did a refresh. The Entity Framework works just fine and is able to connect and retrieve from the database. However the App_Data folder is empty.
Here is are my connection strings:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-UsingEntityFramework-20161002112829.mdf;Initial Catalog=aspnet-UsingEntityFramework-20161002112829;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="MovieDBContext" connectionString="Data Source=tcp:xxxxxxxxxx.net;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxxx;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Check your web.config and notice the connectionString and see the data source, maybe it is creating it under your SQL Server not inside the App_Data
The MDF File will be created when the database is created, and since this is a code first, the database will not be created unless you run the application and start connecting to the database, EF will create the database if it doesn't exist and will compare the schema to the schema in the Migrations folder and it will update the database if it is not up to date.
You can also open Nu Get Package Manager and run the command Update-Database to create and update the database.
My development machine has multiple versions of LocalDb. After running an initial EF migration the database was created in (localdb)\MSSQLLocalDB (SQL Server 12.0.4213...). I expected it to land in (localdb)\v11.0 (SQL Server 11.0.3000...).
The connection string in app.config is
<add name="HomeCinemaDan"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=HomeCinemaDan;Integrated Security=SSPI; MultipleActiveResultSets=true"
providerName="System.Data.SqlClient" />
What configuration line does EF migrations read to determine which db version to install to?
Background: I'm following this tutorial and I've reached the end of the Data Repositories segment (I'm at the line that reads update-database -verbose). I've changed the database name to HomeCinemaDan.
I have problem with my ASP.NET MVC app which is using SQLSERVER 2012 Expresss for security and somehow this is conflicting with my Firebird installation which is not used in this case. Getting exception like this:
An error occurred creating the configuration section handler for system.data: Column 'InvariantName' is constrained to be unique.
Value 'FirebirdSql.Data.FirebirdClient' is already present.
I have tried to enter in my web.config this:
<remove invariant="FirebirdSql.Data.FirebirdClient"/>
but that didn't work, what I have finally do I have removed this firebird entry from machine.config:
<system.data>
<DbProviderFactories>
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient, Version=3.0.2.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c"/><add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient, Version=3.0.2.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c"/></DbProviderFactories>
and that worked out, but th is not ideal solution bcause I still need firebird to use sometimes. Anyway to disable this entry temporarily in app web,config? Also, why I am getting such conflict to start with anyway?
thanks
You have the same record in machine.config twice. Remove one and you'll be fine.
I have a similar problem and ended up with a different solution.
What happen is that I started developing my Web application in the default (root) folder IIS creates.
After that, for testing purposes I changed this option to work in a deeper folder in the same domain:
I added the name and clicked "Create Virtual Directory". The application ran but gave me the similar problem.
What happen is that when I created the second virtual directory IIS express leave the first one there pointing to the same location. So I have the same app twice sharing Web.config hierarchically.
Solution to my problem
To solve this I just changed the port so the previous created virtual directory is not my root anymore.