gisderdube
gisderdube

Reputation: 487

ASP.NET MVC .mdf file missing

I have a problem that my asp.net mvc application somehow can't create a localdb .mdf file.

For example, I am creating a new web project in VS 2015 and debug it. When I go to register and enter some new user, the app throws an exception that the file cannot be found...

I know there are similar posts, but none of the solutions helped me.

My connection string looks like this:

<add name="DefaultConnection" 
     connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=C:\Users\User\Documents\Visual Studio 2015\Projects\Auth1\Auth1\App_Data\aspnet-Auth1-20160121104112.mdf;Initial Catalog=aspnet-Auth1-20160121104112;Integrated Security=True" 
     providerName="System.Data.SqlClient" />

I already tried changing the keyword AttachDbFilename to

|DataDirectory|\aspnet-Auth1-20160121104112.mdf

I tried playing around with the Data Source.

I tried giving permission to the the SQL Server user to the folder...

I checked that VS, SQL Server 2014 and the Windows User are all using the same user.

I mean, how can a project from scratch already have a bug?

Upvotes: 1

Views: 2261

Answers (5)

salli
salli

Reputation: 782

If you are working with C:\inetpub\wwwroot and you are using IIS express, make sure that app_data folder in the project is given full access for the current logged in user.

Upvotes: 0

Mihail Stancescu
Mihail Stancescu

Reputation: 4138

  1. Is this a new project?

  2. Have you build and run the project?

That database will be created by the asp.net identity when a user tries to login/register. Afterwards you'll see the mdf file in the directory you specified in the connection string.

Upvotes: 0

oneNiceFriend
oneNiceFriend

Reputation: 6891

You can try to create a database inside your project(or in your solution) from scratch. Lets see whats going to happen? If there will be error, the error message will give us a hint.

Upvotes: 0

Chetan Hirapara
Chetan Hirapara

Reputation: 694

Remove all the thinigs for entity related to .mdf and add again from start point

This will be automatic add all required reference and artifacts.

Upvotes: 0

RoteS
RoteS

Reputation: 1445

Have you tried removing this part entirely?

(the part being : AttachDbFilename=C:\Users\User\Documents\Visual Studio 2015\Projects\Auth1\Auth1\App_Data\aspnet-Auth1-20160121104112.mdf)

if that doesn't work have you installed localdb?

Upvotes: 2

Related Questions