2015-05-28 156 views
0

我得到这个错误:CREATE DATABASE失败,实体框架:该系统找不到指定的文件

An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code 

Additional information: Directory lookup for the file "C:\pub\LSK\Dev\src\LSK.Services\LSK.Services\App_Data\LSK.Packets.mdf" failed with the operating system error 2(The system can not find the specified file). 

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



using (var context = new LDTContext()) 
      { 
       context.Packets.AddRange(packets); // Here occurs the exception 
       context.SaveChanges(); 
      } 


public class LDTContext : DbContext 
    { 
     public LDTContext() 
      : base("name=LDTContext") 
     { 
      Configuration.LazyLoadingEnabled = true; 
      Configuration.ProxyCreationEnabled = true; 
      Configuration.ValidateOnSaveEnabled = true; 
      Configuration.AutoDetectChangesEnabled = true; 
      Configuration.UseDatabaseNullSemantics = false; 
     } 


     public DbSet<Packets> Packets{ get; set; } 

    } 

在我的app.config:

<add name="LDTContext" connectionString="Server=(LocalDb)\LSK;Initial Catalog=LSK.Packets;Integrated Security=true;AttachDBFilename=|DataDirectory|\LSK.Packets.mdf" providerName="System.Data.SqlClient" /> 

为什么不创建数据库第一次AddRange()时,数据被推入表中?

+0

是否路径中(C:\酒吧\ LSK \开发的\ src \ LSK.Services \ LSK.Services \ App_Data文件)?你有写入权限吗?文件LSK.Packets.mdf已经存在了吗?尝试将其移出并重复。 –

+0

well App_Data只存在于LSK.Services \ – Pascal

回答

相关问题