繁体   English   中英

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

[英]What should the providerName attribute be when adding a connection string for an SQL database?

我正在使用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属性的末尾输入了版本号,但是我找不到将其更改为哪个版本,我尝试了各种数字,但无济于事。

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

以下几节已定义,与连接字符串无关。

您在@RenderSection("scripts", required: false)中缺少@RenderSection("scripts", required: false)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM