2014-02-12 356 views
5

我正在开发一个笑话web应用程序。[Win32Exception(0x80004005):系统找不到指定的文件]

我使用C#,实体框架,MVC和代码优先。

现在,当我尝试读出我的数据库中的某些东西时,出现在标题中的错误出现了。我不知道该找什么。 我抬起头,谷歌,但我并没有完全得到答案......

我尽量提供一切你可以需要知道代码:

public class Context : DbContext 
{ 
    public DbSet<Categorie> Categories {get;set;} 

    public Context() : base("Witze_DB") 
    { 
    } 
} 

public class HomeController : Controller 
{ 
    private Context db; 

    public HomeController(Context db) 
    { 
     this.db = db; 
    } 

    public ActionResult Index() 
    { 
     var allCats = db.Categories; 
     return View(allCats); 
    } 
} 

这是Index.cshtml文件:

@model IEnumerable<Witze.Categorie> 

@{ 
ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 

<p> 
@Html.ActionLink("Create New", "Create") 
</p> 
<table> 
<tr> 
    <th> 
     @Html.DisplayNameFor(model => model.Name) 
    </th> 
    <th></th> 
</tr> 

@foreach (var item in Model) { 
<tr> 
    <td> 
     @Html.DisplayFor(modelItem => item.Name) 
    </td> 
    <td> 
     @Html.ActionLink("Edit", "Edit", new { id=item.CategorieId }) | 
     @Html.ActionLink("Details", "Details", new { id=item.CategorieId }) | 
     @Html.ActionLink("Delete", "Delete", new { id=item.CategorieId }) 
    </td> 
</tr> 
} 

</table> 

这是我得到的:(这将是更长的时间,如果它确实有助于你我会后休息为好,它只是更System.Data.SqlClient ...)

Server Error in '/' Application. 
-------------------------------------------------------------------------------- 


The system cannot find the file specified 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified 

Source Error: 





    Line 18:  </tr> 
    Line 19: 
    Line 20: @foreach (var item in Model) { 
    Line 21:  <tr> 
    Line 22:   <td> 

Source File: c:\Users\a80815067.EISLAB\Documents\Visual Studio 2012\Projects\Witze_Logik\Witze_Web\Views\Home\Index.cshtml Line: 20 

Stack Trace: 





[Win32Exception (0x80004005): The system cannot find the file specified] 

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)] 
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5295887 
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +242 

如果您需要任何其他信息,只需询问。

+0

您是否读过整个异常?似乎连接到SQL Server时出现问题。 –

回答

4

看一看堆栈跟踪,你有以下错误:

The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.

最可能的是,你的连接字符串无效。

+0

谢谢=)似乎我不知道我是怎么做的整个连接到数据库.. ^^ 现在我得到正确的连接字符串在正确的地方=) – WTFisOssi

相关问题