C# 缺少用于发布的连接字符串
我正在学习制作一个MVC项目,现在我正在尝试学习如何发布它。我遇到了这样一个问题:我必须配置我的连接字符串,但我没有(我想)任何连接字符串,或者只是在我的C# 缺少用于发布的连接字符串,c#,asp.net,asp.net-mvc,entity-framework,C#,Asp.net,Asp.net Mvc,Entity Framework,我正在学习制作一个MVC项目,现在我正在尝试学习如何发布它。我遇到了这样一个问题:我必须配置我的连接字符串,但我没有(我想)任何连接字符串,或者只是在我的web.config中丢失了连接字符串 我必须添加它,还是可以在其他地方找到?(我试图添加一个,但我想先问一下,或者做些研究,以避免更多的问题,因为我还没有那么好) Web.config <?xml version="1.0" encoding="utf-8"?> <configuration> <configSe
web.config
中丢失了连接字符串
我必须添加它,还是可以在其他地方找到?(我试图添加一个,但我想先问一下,或者做些研究,以避免更多的问题,因为我还没有那么好)
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
在
元素中添加一个与
标记平行的部分,例如:
<configuration>
<connectionStrings>
<add name="DbConnection" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=randomDatabaseName;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
在应用程序中,您可以使用声明的名称调用数据库:DbConnection。
您可以向该部分添加任意数量的连接字符串
为了回答您的问题,您可以在需要时自己在应用程序中构造字符串或将其写入配置文件中。如果您使用的是entityframework,我相信将连接字符串放在web.config中是eaiser的责任 您需要将其添加到web.config