Connection error

Posted on 2008-01-31
Medium Priority
Last Modified: 2013-12-17
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?


Question by:11login
  • 2
  • 2
LVL 22

Accepted Solution

p_davis earned 750 total points
ID: 20788431
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

Author Comment

ID: 20788792
Ok. I have deleted the file. Same error. No new ldf-file is created.
LVL 22

Expert Comment

ID: 20788887
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>>?

Author Comment

ID: 20789257
[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!


Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question