Using ObjectDataProvider as binding source gives SQL error

631 views Asked by At

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 database 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.
1

There are 1 answers

0
Kaare Mai On BEST ANSWER

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