开发者

Using ObjectDataProvider as binding source gives SQL error

I have a weird problem that i can't figure out a solution for:

I've made a little WPF app written in C# that uses an attached SQL Server Express .mdf datab开发者_如何学运维ase which i then manipulates through LINQ.

I have a ListView on the form which datacontext is set to .DataContext = dr.FindAllBuyOrders() which returns an IQueryable BuyOrder object. This all works fine. however, when i do the same through xaml with the ObjectDataProvider:

<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>

then i get the following error:

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.


I found the solution:

The connectionstring was stored with a relative path to the database instead of the absolute one. See more at this link:

Embedding SQL Express to use with Linq to SQL and User Instances can be a pain

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜