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" />
Related
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>
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'm getting the following error when I try and run a web site in production via its URL:
ProjectName.ssdl(2,2) : error 0152: No Entity Framework provider found
for the ADO.NET provider with invariant name 'System.Data.SqlClient'.
Make sure the provider is registered in the 'entityFramework' section
of the application config file.
My web.config file:
<connectionStrings>
<add name="ProjectNameEntities" connectionString="metadata=res://*/ProjectNameModel.csdl|res://*/ProjectNameModel.ssdl|res://*/ProjectNameModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SomeServer;initial catalog=SomeDB;User Id=SomeID;Password=SomePassWord;App=EntityFramework"" providerName="System.Data.EntityClient"/>
</connectionStrings>
I don't have an entityFramework section in my config file (as per the error) but the project runs fine from Visual Studio in the production environment.
To clarify - via the URL I get an error, via Visual Studio it works fine.
I read this post which apparently solves the issue with WPF app publishing which has SQL Server Compact dependency. I went through all the steps prescribed by the author of this post but it just doesn't work for me. Once I add all the DLLs from SQL Server Compact "private" folder my app crashes on startup. The difference is that I use .NET 4.5 while the example deals with 4.0 I am not sure if that is the core of the problem but it just doesn't work with those settings.
My app is crashing with the following exception :
System.Windows.Markup.XamlParseException
Here is my app.config (including add on from the article ) :
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="TypeAppRelease.Properties.Settings.MyDatabase_1ConnectionString"
connectionString="Data Source=D:\XXXXXX\XXXXX\XXXXXXX\externals\MyDatabase#1.sdf;Password=XXXXXXX;Persist Security Info=True"
providerName="Microsoft.SqlServerCe.Client.4.0" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0"/>
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.1,
Culture=neutral,
PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
One more thing. I came to this because doing just ClickOnce publishing produced installation file which didn't work complaining that
The application is missing required files ....
So that lead me to the solution I linked above which also seems not to work.
Update:
I would like to extend on this problem because until not I haven't resolved it.
I decided to put aside ClickOnce deployment and just test Debug/Release builds on 2 machines:1) With SQL Compact Server installed ;2) Has only NET framework installed.
The App works ok on the first machine and fails on the second.That is pretty logical because the first one has Compact SQL installed and running.
Next I removed the server installation from the first machine and ran the app again.It still works , but not for the second PC .The error I am getting is
System.IO.FileLoadException
I can't figure out why I am getting it and why I am not getting the same on the first machine.
Maybe it is 64 /32 bit OS thing? PC1 runs Windows 7 64bit while PC2 x86.
I you use ADO.NET objects (SqlCeCommand, DataSet) instead of Entity Framework (as described in my blog post) you must reference System.Data.SqlServerCe.dll in your project folder (assembly version 4.0.0.1) and NOT the dll in your GAC (assembly version 4.0.0.0). I have updated my blog post with that information.
I have a UI & Library project for the solution where I'm having the problem. The library project uses Entity Framework & the unit tests work OK with it. The project is a C# 4.0 WPF application.
To try to get a basic EF line of code working I copied the connection string from the Library project app.config to the UI project app.config.
When I run the project with a simple EF test couple of lines (see below) I get the error below. Note that both projects are set to use the .NET Framework 4 already. I do use other libraries such as Quartz.Net, however everything works fine until I include the below line.
Any suggestions re how to correct this issue?
// Test ONly
using (var dbContext = new Model1Container())
{
Debug.WriteLine("Total Usages = " + dbContext.Usages.Count());
}
Error:
"Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."
Connection String I copied into the UI project app.config
<connectionStrings>
<add name="Model1Container" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string='data source="C:\Documents and Settings\Owner\My Documents\My Dropbox\source\MyInternetUsage\MyInternetUsageLibrary\MyInternetUsage.sqlite"'" providerName="System.Data.EntityClient" />
</connectionStrings>
Add the following directive to your app.config
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
This should fix your mixed mode problem.