我是ASP.NET的新手,我在尝试发布我的应用程序时遇到了以下问题。当我单击“打包/发布SQL”按钮然后继续尝试从我的web.config文件导入数据库条目时,我收到一条错误,上面写着“在web.config中找不到连接字符串”
正如您所看到的,我的Web.config
中存在连接非常感谢任何帮助。
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<connectionStrings> <!--<clear/>
<remove name="LocalSqlServer"/>-->
<add providerName="System.Data.SqlClient" name="LocalSqlServer" connectionString="server=mydatabase\SqlExpress; database=AssetManager.Models.AssetManagerContext; Integrated Security=SSPI " />
</connectionStrings>
<system.web>
<globalization culture="auto" uiCulture="auto" />
<roleManager enabled="true" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Calendar/Index?showLogin=1" timeout="2880" />
</authentication>
<membership defaultProvider="AssetManagerMembershipProvider">
<providers>
<clear/>
<add name="AssetManagerMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile inherits="AssetManager.Models.ProfileModel" defaultProvider="AssetManagerProfileProvider">
<providers>
<clear/>
<add name="AssetManagerProfileProvider" type="System.web.Profile.SqlProfileProvider" connectionStringName="LocalSqlServer"/>
</providers>
</profile>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.net>
<mailSettings>
<smtp from="nathandavies.markdrummond@email.com">
<network
host="smtp.gmail.com"
port="587"
password="!password"
userName="nathandavies.markdrummond@email.com"
/>
</smtp>
</mailSettings>
</system.net>
</configuration>
答案 0 :(得分:0)
尝试修改以下行的连接字符串:
对于Sql Server身份验证:
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;database=AssetManager.Models.AssetManagerContext;User ID=yourusername;password=yourpassword" providerName="System.Data.SqlClient"/>
</connectionStrings>
在相应的属性中输入UserName和Password。
用于Windows身份验证
<connectionStrings>
<add name="LocalSqlServer"
connectionString="Data Source="localhost";
Initial Catalog=AssetManager.Models.AssetManagerContext;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
希望它有效。