EntityConnection错误在配置中找不到指定的命名连接

时间:2014-03-06 12:46:13

标签: c# wpf connection entity ado.net-entity-data-model

嗯,我知道有一些话题,但相信我 - 我尝试了一切,但仍然没有回答如何解决这个问题。

错误: 指定的命名连接在配置中找不到,不打算与EntityClient提供程序一起使用,或者无效。

在app.config中我有连接字符串:

   <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在我的模型中:

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"

在我的电脑中一切都很棒。但是当我将可执行文件复制到我的朋友PC时,我遇到了这些错误:

  

InerException:

     

来源:System.Data.Entity

     

StackTrace:w   System.Data.EntityClient.EntityConnection.ChangeConnectionString(字符串   newConnectionString)w   System.Data.EntityClient.EntityConnection..ctor(字符串   connectionString)w   System.Data.Objects.ObjectContext.CreateEntityConnection(字符串   connectionString)w xxxxx.Additions.GetProductsEntities..ctor()
  w xxxxx.Additions.GetReturnEntities.returnProductEntities(Nullable 1 cID, Nullable 1 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(对象   resizedCompositionTarget)w   System.Windows.Media.MediaContext.RenderMessageHandler(对象   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&amp;处理)w   MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam,   IntPtr lParam,Boolean&amp;处理)w   MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)w   System.Windows.Threading.ExceptionWrapper.InternalRealCall(代表   callback,Object args,Int32 numArgs)w   MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象   source,Delegate方法,Object args,Int32 numArgs,Delegate   catchHandler)

     

TargetSite:Void ChangeConnectionString(System.String)

     

数据:System.Collections.ListDictionaryInternal

     

----------------------------------------------- --------------------------------------------- System.ArgumentException Stos: (堆栈)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.Nullable 1<Int32>, System.Nullable 1)w xxxxx.App.loadEntities()w   xxxxx.App.OnStartup(System.Windows.StartupEventArgs)w   System.Windows.Application。&lt; .ctor&gt; 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()

在这个问题上,我的模型与app.config位于同一个文件夹中。我试图将connectionString直接复制到

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

但仍有错误,数据源不是连接字符串等的正确值。

请帮帮我。

谢谢!

0 个答案:

没有答案