1

我有一个奇怪的问题,我无法找到解决方案:

我制作了一个用 C# 编写的小 WPF 应用程序,它使用附加的 SQL Server Express .mdf 数据库,然后我通过 LINQ 对其进行操作。

我在表单上有一个 ListView,其中 datacontext 设置为.DataContext = dr.FindAllBuyOrders()返回 IQueryable BuyOrder 对象。这一切都很好。但是,当我使用 ObjectDataProvider 通过 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.
4

1 回答 1

2

我找到了解决方案:

连接字符串与数据库的相对路径而不是绝对路径一起存储。在此链接中查看更多信息:

嵌入 SQL Express 以与 Linq to SQL 和用户实例一起使用可能会很痛苦

于 2009-10-24T11:28:22.627 回答