Tuesday, March 04, 2008 12:37 PM
When I run this code:Code Snippet
DataContext dc = new DataContext(@"C:\Northwind.mdf");
IQueryable<Customer> query = from cust in dc.GetTable<Customer>()
where cust.Country == "USA"
foreach (Customer c in query)
I get this error Message:
An attempt to attach an auto-named database for file C:\Northwind.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Its true I have a Northwind.mdf at C:\program files\sql server\mssql1 but I wonder if that would cause a problem.
More likely it cannot be opened, but I got the code sample from Pro LINQ by Joseph Rattz
Tuesday, March 04, 2008 4:13 PM
SQL server gets confused because it remembers (keeps a catalog of) all the previous databases you've attached and identifies them by their common catalog name. So when you try to attach a different version of the database or one that simply has the same catalog name, it can't handle it. You'll need to formally detach the prior one by using SQL Management Studio or equivalent to remove the entry in its memory.