Question

I am using Visual Studio 2012 on Windows 8.

I create a new [Empty Web Application], follow common code-first (new database) steps to use EF, which are:

  1. Create a model class,
  2. Create a model-context class,
  3. Access some data using model-context class in a web page.

But when I run that page, I get:

Directory lookup for the file "C:\Users\XUHAI\Documents\Visual Studio 2012\Projects\EF\EmptyWeb\App_Data\EmptyWeb.WebContext.mdf" failed with the operating system error 2.

CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

While I create [Web Forms] or [MVC] project, and perform the same steps, everything goes fine.

Était-ce utile?

La solution

Operating system error 2 is "File not found".

Make sure the directory "C:\Users\XUHAI\Documents\Visual Studio 2012\Projects\EF\EmptyWeb\App_Data" exists.

Check your connection string for errors.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top