ASP.NET database ALWAYS corrupted

I am new to ASP.net (I have been building the main applications for about 2 weeks) and am amazed at the big problem with my databases.

I created a simple email application with a login system. A few days ago everything worked perfectly.

But for some reason, every time I try to access the database file with my programs, getting the following error:

* Server error in application "/". The database file may be corrupted. Run the recovery utility to check the database file. [Database name = C: \ Users \ ArvinAsus \ Documents \ Visual Studio 2010 \ Projects \ mailer \ App_Data \ Database.mdf] Description: An unhandled exception occurred during the execution of the current web request. View the stack trace for more information about the error and its occurrence in the code. Exception Details: System.Data.SqlServerCe.SqlCeException: The database file may be corrupted. Run the recovery utility to check the database file. [Database name = C: \ Users \ ArvinAsus \ Documents \ Visual Studio 2010 \ Projects \ mailer \ App_Data \ Database.mdf] *

This error is always displayed in each database. Wether I use a database that worked in the past, or just created a new empty db.

I get the feeling that this problem has nothing to do with db corruption, but with another problem that I am facing:

When I have my local database connected in the server explorer, I can add tables - populate the tables with data, the test connection will always be successful. when I try to connect to the database through my program:

* Exception Details: System.Data.SqlServerCe.SqlCeException: file access violation exists. Another way might use a file. [C: \ Users \ ArvinAsus \ Documents \ Visual Studio 2010 \ Projects \ mailer \ App_Data \ Database.mdf] *

Then I close the connection in the server explorer and the error disappears, leaving an error with an error.

I am completely stuck with this. Anyone who has an idea to turn me on again?

early.

PS: Im using Visual Studio 2010 Professional

+4
source share
3 answers

The .MDF file is NOT a SQL Compact Edition database file, but a SQL Server data file. You must use SQL Server (Express, Professional, or any other version) to access and bind to your database using your own SQL client, OleDB, or any other Data Connector instead of SQLServerCE.

+3
source

Your exception tells you what is happening: There is a file sharing violation. A different process might be using the file. There is a file sharing violation. A different process might be using the file. Many processes do not release files even after using them. You must use the actual instance of SQL Server (even if it is expressed) in order to be able to manage connections in the database.

I supported @Y. Ecarri answers because I think it has the right solution, but the most likely reason you are facing a file sharing conflict is the development environment itself. If you use the built-in Cassini server (most likely) that comes with the IDE debugger, it will support the development web server in standby mode between debugging sessions. Since the first session stores a copy of your .mdf in memory live and saved, subsequent debugging sessions will not be able to access it, although it should be available. To free the file, you need to stop debugging, then right-click on any icons in the taskbar representing instances of the development web server and tell them Stop .

+2
source

The problem with me is that my web.config file has been modified. The physical location of the database has been changed and this error has been selected. The database was still there, but it did not point to the right place.

To verify that this is not a problem, double-check the web.config file. Hope this helps someone.

0
source

Source: https://habr.com/ru/post/1445524/


All Articles