EntityConnection error The specified named connect

2019-09-19 01:51发布

问题:

Well, I know there was some topic about that, but believe me - i tried everything and still didn't get answer how to solve that issue.

Error: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

In app.config i have connection string:

   <add name="GetProductsEntities" connectionString="metadata=res://*/GetProductsModel.csdl|res://*/GetProductsModel.ssdl|res://*/GetProductsModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(local);initial catalog=mainDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

samae as in my model when I click properties:

metadata=res://*/GetProductsModel.csdl|res://*/GetProductsModel.ssdl|res://*/GetProductsModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(local);initial catalog=mainDB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"

In my PC everything works great. But when I copy executable file to my friend PC, im having those errors:

InerException:

Source: System.Data.Entity

StackTrace: w System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) w System.Data.EntityClient.EntityConnection..ctor(String connectionString) w System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString) w xxxxx.Additions.GetProductsEntities..ctor()
w xxxxx.Additions.GetReturnEntities.returnProductEntities(Nullable1 cID, Nullable1 wID) w xxxxx.LoginWindow.loadEntities() w xxxxx.LoginWindow.Window_Loaded(Object sender, RoutedEventArgs e) w System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) w System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) w System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) w System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) w System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent) w System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root) w MS.Internal.LoadedOrUnloadedOperation.DoWork() w System.Windows.Media.MediaContext.FireLoadedPendingCallbacks() w System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() w System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) w System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) w System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget) w System.Windows.Interop.HwndTarget.OnResize() w System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam) w System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) w MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) w MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) w System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) w MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

TargetSite: Void ChangeConnectionString(System.String)

Data: System.Collections.ListDictionaryInternal

-------------------------------------------------------------------------------------------- System.ArgumentException Stos: (Stack) w System.Data.EntityClient.EntityConnection.ChangeConnectionString(System.String) w System.Data.EntityClient.EntityConnection..ctor(System.String) w System.Data.Objects.ObjectContext.CreateEntityConnection(System.String) w xxxxx.GetProductsEntities..ctor() w xxxxx.Additions.GetReturnEntities.returnProductEntities(System.Nullable1<Int32>, System.Nullable1) w xxxxx.App.loadEntities() w xxxxx.App.OnStartup(System.Windows.StartupEventArgs) w System.Windows.Application.<.ctor>b__1(System.Object) w System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) w MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) w System.Windows.Threading.DispatcherOperation.InvokeImpl() w System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) w System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) w System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) w System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) w System.Windows.Threading.DispatcherOperation.Invoke() w System.Windows.Threading.Dispatcher.ProcessQueue() w System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) w MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) w MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) w System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) w MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) w System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) w MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
w MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) w System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) w System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) w System.Windows.Threading.Dispatcher.Run() w System.Windows.Application.RunDispatcher(System.Object) w System.Windows.Application.RunInternal(System.Windows.Window) w System.Windows.Application.Run(System.Windows.Window) w xxxxx.App.Main()

At this momment my Model is in the same folder as app.config. I tried to copy connectionString directly into

public GetProductsEntities() : base("name=GetProductsEntities", "GetProductsEntities")

but still have errors that Data source is not proper value for connection string etc..

Help me, please.

Thanks!