Abd elhedi hlel Abd elhedi hlel - 3 months ago 11
ASP.NET (C#) Question

Host database (SQL Server) errors

I am trying to host my website and the database, but I have same problems and I don't know why .

This is the error message:

enter image description here

Answer

There could be several reasons that you are facing this error.

You could try following solutions:

  • This problem could be caused by UAC (User Account Control);

Although your user account is a member of Administrators group, the UAC in Windows 7 doesn't allow you to do administrator things unless you run programs "as administrator".

In this case you could do two things:

  • Run SQL Server Management Studio as an Administrator

  • You can also disable UAC. Go to the Control Panel -> User Accounts -> Change User Account Control Settings-> Set to "Never notify"

  • SQL Server database engine service account must have permissions to read/write in the new folder;

To fix, do the following:

Add the Administrators Group to the file security permissions with full control for the Data file and the Log File and then attach the database

  • Unblocking the zipped files;

Also check that mdf and ldf files are not blocked. Right click the .mdf / .ldf / .bak file > Properties > Unblock -> Apply)

  • Give full permissions to the folder where your .mdf / .ldf / .bak file is
  • Give full permissions to .mdf / .ldf / .bak file
  • If you do not want to play with permissions then you can also try this;

Copy your .mdf / .ldf / .bak file to default SQL backup location which has all the necessary permissions. You do not need to fiddle with anything else. In SQL SERVER 2012, this location is

C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup

  • Follow below steps to Attach the database;
  • Place the .mdf and .ldf in C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA
  • Right click on 'Databases' in the object explorer and select 'Attach'
  • In the Attach Databases dialog box, Click on 'Add' button in the databases to attach: .mdf and .ldf files
  • Navigate to the .mdf file location C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Data.mdf and click Ok. To Add the .ldf file you can do two things:
    • Select the existing .ldf file
    • Delete the existing .ldf file, as the SQL server will create one later once the database is attached
  • Now the database 'Data' is created in SQL Sever