添加SQL数据库的连接字符串时,providerName属性应该是什么?

时间:2013-11-15 22:03:25

标签: c# sql sql-server visual-studio-2012 connection-string

我正在使用Visual Studio 2012和SQL Server 2014 CTP2来构建简单的网页(使用C#和剃刀标记)。到目前为止,可以访问和查看数据库,但是用户尝试向其添加新项目或编辑现有项目会引发以下错误:

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Scripts".

供参考,这是我的_Layout.cshtml文件

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8" />

    <title>@ViewBag.Title</title>

    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery-1.8.2.min.js")"></script>
    <script src="@Url.Content("~/Scripts/modernizr-2.6.2.js")"></script>
</head>

<body>
    <ul id="menu">
        <li>@Html.ActionLink("Home", "Index", "Home")</li>
        <li>@Html.ActionLink("Movies", "Index", "Movies")</li>
        <li>@Html.ActionLink("About", "About", "Home")</li>
    </ul>

    <section id="main">
        @RenderBody()
        <p>Copyright W3schools 2012. All Rights Reserved.</p>
    </section>

</body>

这是我在Web.config中的数据库的连接字符串:

<add name="MovieDBContext" connectionString="Data Source=|DataDirectory|\Movies.sdf" providerName="System.Data.SqlServerCe.4.0"/>

我认为问题在于providerName属性。当我将它更改为System.Data.SqlClient时,数据库根本不会显示,我收到以下错误(仅在停止调试过程后才会出现):

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: 26 - Error Locating Server/Instance Specified)

我有一种感觉,我只是在providerName属性的末尾有版本号错误但我无法找出我需要更改它的版本,我尝试了大量的数字但是没有果。

我是这个框架的新手,所以请保持温柔:)

1 个答案:

答案 0 :(得分:0)

已定义以下部分与连接字符串无关。

您的_layout.cshtml中缺少@RenderSection("scripts", required: false)

在任何视图中,您可能已定义@section Script {}。您必须从视图中删除@section Script {}或将@RenderSection()添加到_layout.cshtml。