Connection error

Hi there,

I have an old project that I have reopened in a new computer. It is a fairly simple c# application using a Sql Express database for storing user account data. Problem is that when I try to connect to the database from within code as below:

string CommandText = string.Format("SELECT * FROM {0} WHERE {1}", TableName, Filter);
SqlCommand command = new SqlCommand(CommandText, Connection);

... I get the following error:

Cannot create file 'C:\Users\x\Documents\Visual Studio 2005\Projects\y\ServiceLogOnline\z\z_log.LDF' because it already exists. Change the file path or the file name, and retry the operation.
Could not open new database 'z'. CREATE DATABASE is aborted.
Cannot attach the file 'C:\Users\x\Documents\Visual Studio 2005\Projects\y\y\App_Data\z.mdf' as database 'z'.
File activation failure. The physical file name "C:\Documents and Settings\Administratör\Mina dokument\Visual Studio 2005\Projects\y\y\App_Data\z_log.ldf" may be incorrect.

I have tried giving 'Everyone' permission to do everything to the app_data folder, but it still does not work. What am I doing wrong?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rename the old z_log.Ldf or make a back up of it. just so you can revert back if you need to.-- then respectively, (if you renamed it) run your program, (if you made a backup of it) delete it and run your program

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
11loginAuthor Commented:
Ok. I have deleted the file. Same error. No new ldf-file is created.
you get the exact same error. specifically
<<Cannot create file 'C:\Users\x\Documents\Visual Studio 2005\Projects\y\ServiceLogOnline\z\z_log.LDF' because it already exists>>?
11loginAuthor Commented:
[ashamed] I realize that I am just plain stupid. I removed the ldf-file from wwwroot, but that is the published location. When i try to debug i debug from another directory. When removing the ldf-file from the correct directory it actually works like a charm. Great help, thank you!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.