ObjectDataprovider를 바인딩 소스로 사용하면 SQL 오류가 발생합니다
-
06-07-2019 - |
문제
해결책을 찾을 수없는 이상한 문제가 있습니다.
첨부 된 SQL Server Express .MDF 데이터베이스를 사용하여 LINQ를 통해 조작하는 C#로 작성된 작은 WPF 앱을 만들었습니다.
DataContext가 설정 한 양식에 대한 ListView가 있습니다. .DataContext = dr.FindAllBuyOrders()
iqueryable buyorder 객체를 반환합니다. 이 모든 것이 잘 작동합니다. 그러나 객체 dataprovider와 함께 XAML을 통해 동일하게 할 때 :
<ObjectDataProvider MethodName="FindAllBuyOrders" ObjectType="{x:Type local:DataRepository}" x:Key="dataBuyOrders" />
<ListView Name="listViewBuyOrders" VerticalContentAlignment="Top" ItemsSource="{Binding Source={StaticResource dataBuyOrders}}" ItemTemplate="{StaticResource listViewBuyOrders}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
그런 다음 다음 오류가 발생합니다.
An attempt to attach an auto-named database for file
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Data.mdf
failed. A database with the same name exists, or specified file
cannot be opened, or it is located on UNC share.
해결책
해결책을 찾았습니다.
ConnectionString은 절대 대신 데이터베이스 대신 데이터베이스에 대한 상대 경로로 저장되었습니다. 이 링크에서 자세히보기 :
제휴하지 않습니다 StackOverflow