views:

228

answers:

1

I have a single-user Win Forms application that uses an SQL Server Express database via ADO.NET. I want to add more to my app, but by using Linq to Sql (while I learn Linq to Sql). I am unable to see the database in two places simultaneously. Either I can see it in the original code using ADO, or I can see it with the new code using Linq to SQL. Using the data with one method makes the other refuse to see it. Previously, I enabled the new Linq to SQL code to see it by copying the database's containing directory, with the database as well, to another directory name and getting at it with L2S before getting it with ADO. This allowed me to see that my Linq to SQL code worked (hooray!). However, now I can't use that new database with the original code with ADO because "Access is denied(5).". What am I doing wrong? How do I make it share?

EDIT: Removed the part of the question asking about attaching in SQL Server; that part of the problem is that I need to run SQL Server as an admin (Vista) and now it attaches. /EDIT

Now that I am using L2S, when I try to open the connection in ADO.NET, I get "Unable to open the physical file "C:\PRICINGtests\PRICING.MDF". Operating system error 5: "5(Access is denied.)". An attempt to attach an auto-named database for file C:\PRICINGtests\PRICING.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."

A: 

Have you got two separate connection strings here? I presume you have and they're both trying to attach the mdf with the same database name on to your sql server which isn't allowed.

Have you ADO & Linq code use the same single connection string and they'll both use the same database.

Chris W
Thanks, Chris. I don't know how to get at the full connection string with Linq, just with the "DataContext db = new DataContext (@"C:\PRICINGtests\PRICING.MDF");", and I lifted that string directly out of the app config file to make sure there were no typos. In any case, this is a small program, and I am turning off entire sections of it at a time; during a single execution I am only attempting to run with one data connection method. Running the database the first time using Linq only made it so that I couldn't later run it using ADO only.
CindyH