Entity Framework does not work if running with pendrive or server

My application was created using .Net 4.0 Client Profile, WPF, EF 6.0, Code-First, 2 dataproviders (SQL Server CE and MySQL).

If I copy the debug / release folder to the local file path , it works fine.

But if you copy this folder to pendrive or put it in the server folder . The first time I need to create DbContextor call a database initializer, its error ended with the following error ( J:- my pendrive):

The type initializer for "System.Data.Entity.Internal.AppConfig" threw an exception An error occurred while creating the configuration section handler for the Entity Framework: the request failed. ( J: \ USERS \ George \ Release \ app.Config line 6)

System.TypeInitializationException: type initializer for 'System.Data.Entity.CreateDatabaseIfNotExists 1 [DG.Apps.JLM.Questoes.Domain.Contexts.QuestoesContext] .. ctor () in System.Void DG.Apps.JLM.Questoes.Presentation. App.OnStartup (System.Windows.StartupEventArgs e) in j: \ USERS \ George \ Release \ Common \ Common \ Apps \ JLM \ DG.Apps.JLM.Questoes \ DG.Apps.JLM.Questoes.Presentation \ App.xaml .cs: ​​line 30 in Object System.Windows.Application. <.ctor> b__1 (System.Object is not used) in Object System.Windows.Threading.ExceptionWrapper.InternalRealCall (callback System.Delegate, arguments System.Object, System.Int32 numArgs)1' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. ---> System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for entityFramework: Request failed. ---> System.Security.SecurityException: Request failed.
at System.Void System.Data.Entity.CreateDatabaseIfNotExists




in the MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen object (source System.Object, System.Delegate method, System.Object, System.Int32 numArgs, System.Delegate catchHandler arguments)
in System.Void System.Windows.Threading.DispatcherOperation.InvokeImpl ()
in static System.Void System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext (state System.Object)
with static System.Void System.Threading.ExecutionContext.runTryCode (System.Object userData)
with static System.Void System.Threading.ExecutionContext .RunInternal (System.Threading.ExecutionContext executeContext, System.Threading.ContextCallback callback, System.Object state)
with static System.Void System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executeContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean ignoreSyncCtx)
in static System.Void System.Threading.ExecutionContext.un System.Threading.ExecutionContext executeContext, System.Threading.ContextCallback callback, status System.Object)
in Object System.Windows.Threading.DispatcherOperation.Invoke ()
in System.Void System.Windows.Threading.Dispatcher.ProcessQueue ()
in IntPtr System .Windows.Threading.Dispatcher.WndProcHook (System.IntPtr hwnd, System.Int32 msg, System.IntPtr wParam, System.IntPtr lParam, System.Boolean is being processed)
in IntPtr MS.Win32.HwndWrapper.WndProc (System.IntPtr hwnd, System.Int32 msg, System.IntPtr wParam, System.IntPtr lParam, System.Boolean is processed)
in the object MS.Win32.HwndSubclass.DispatcherCallbackOperation (o
in Object System.Windows.Threading.ExceptionWrapper.InternalRealCall (callback System.Delegate, arguments System.Object, System.Int32 numArgs)
in the object MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen (source System.Object, method System.Delegate, arguments System.Object, System.Int32 numArgs, System.Delegate catchHandler)
in Object System.Windows.Threading.Dispatcher.InvokeImpl (System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, System.Object args , System.Int32 numArgs)
in IntPtr MS.Win32.HwndSubclass.SubclassWndProc (System.IntPtr hwnd, System.Int32 msg, System.IntPtr wParam, System.IntPtr lParam)
in System.Void System.Windows.Threading.Dispatcher.PushFrameImpl (frame System.Windows .DispatcherFrame)
in static System.Void System.Windows.Threading.Dispatcher.PushFrame (System.Windows.Threading.DispatcherFrame)
in static System.Void System.Windows.Threading.Dispatcher.Run ()
in Object System.Windows.Application .RunDispatcher (Ignore System.Object)
in the Int32 System.Windows.Application.RunInternal window (System.Windows.Window window)
in the Int32 System.Windows.Application.Run window (System.Windows.Window window)
in Int32 System.Windows. Application.Run ()
at static System.Void DG.Apps.JLM.Questoes.Presentation.App.Main ()

,

app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
      <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.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="QuestoesContextSqlServerCE" connectionString="Data Source=Questoes.sdf" providerName="System.Data.SqlServerCE.4.0" />
    <add name="QuestoesContextMySQL" connectionString="server=localhost;User Id=root;password=root;Persist Security Info=True;database=questoes" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
  </startup>
</configuration>

wpf OnStartup, SetInitializer

namespace DG.Apps.JLM.Questoes.Presentation
{
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

        Database.SetInitializer(new CreateDatabaseIfNotExists<QuestoesContext>());

, , , , pendrive

+3
1

. WPF ( .NET Framework 4), Visual Studio 2013 .NET 4.5.2. , , .NET 4.5.2, , , .NET 4.0, , . , , , - , 4.5.2 4.0.

, entityFramework .

<entityFramework>
   <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
   <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
   </providers>
</entityFramework>

- - .

<connectionStrings>
   ...
</connectionStrings>

.

, , . , .

+7

All Articles