在MVC5项目中连接本地数据库时,站点不起作用,

时间:2016-06-30 05:47:56

标签: c# mysql sql-server asp.net-mvc asp.net-mvc-5

我创建了MVC5项目。它的连接服务器数据库运行良好。之后我创建了表相同的数据库,并与我的项目本地SQL服务器配置连接。之后运行我的项目显示错误像这样 '/'应用程序中的服务器错误。

Login failed for user ''.

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.Data.SqlClient.SqlException: Login failed for user ''.

Source Error: 


Line 70:                 if (parameters != null)
Line 71:                 {
Line 72:                     result = await db.QueryAsync<TModel>(sql: procname, param: BuildQueryParameter(parameters), commandType: CommandType.StoredProcedure);
Line 73:                 }
Line 74:                 else

Source File: C:\MVC5_Full_Version\Inspinia_MVC5\Data\Base\HomeSqlDBRepository.cs  Line: 72 


[SqlException (0x80131904): Login failed for user ''.]
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +970
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +802

在注释后显示Error Like本地数据库取消注释服务器db其工作。我使用Appsettings.config

配置了本地和服务器数据库

此处应用设置代码代码:

<?xml version="1.0"?>
<appSettings>

  <add key="webpages:Version" value="2.0.0.0" />
  <add key="webpages:Enabled" value="false" />
  <add key="PreserveLoginUrl" value="true" />
  <add key="ClientValidationEnabled" value="true" />
  <add key="UnobtrusiveJavaScriptEnabled" value="true" />

  <add key="DefaultMembershipName" value="UserName" />

  <add key="SmtpServer" value="relay-hosting.secureserver.net" />
  <add key="SmtpPort" value="25" />
  <add key="UserId" value="thenna41@gmail.com" />
  <add key="Password" value="pixel@1990" />

  <add key="DefaultTheme" value="Theme1"/>
  <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" />
  <!--<add key="Tickandtie" value="Server=123.324.3434.34;Database=montage;User ID=Montage;Password=qbZ4c7?3;Trusted_Connection=False;"/>-->
  <add key="Tickandtie" value="Server=DESKTOP-QD6A981\SQLEXPRESS;Database=montage;Integrated Security=sspi;Trusted_Connection=False;"/>
  <add key="CustomAuthentication.LoginUrl" value="/Account/LogOn" />
  <add key="CustomAuthentication.Cookie.Name" value=".CUSTOM_AUTH" />
  <add key="CustomAuthentication.Cookie.Expiration" value="1" />
  <add key="CustomAuthentication.Cookie.Timeout" value="20" />
</appSettings>

和Web.config

       <?xml version="1.0" encoding="utf-8"?>
<!--
  Więcej informacji dotyczących konfigurowania aplikacji platformy ASP.NET można znaleźć na stronie
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<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" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <connectionStrings>

  <add name="Montagenew" connectionString="data source=DESKTOP-QD6A981\SQLEXPRESS;initial catalog=montagenew;Integrated Security=False;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
 <!--<add name="montageEntities" connectionString="metadata=res://*/Entityframework.Model1.csdl|res://*/Entityframework.Model1.ssdl|res://*/Entityframework.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-QD6A981\SQLEXPRESS;initial catalog=montage;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />--></connectionStrings>


  <system.web>
    <trust level="Full" />
    <customErrors mode="Off" />
    <authentication mode="Windows">

      <forms loginUrl="~/Account/Index" timeout="2880" />
    </authentication>
    <compilation targetFramework="4.5.1" debug="true" />
    <httpRuntime targetFramework="4.5.1" />
  <sessionState timeout="40" mode="InProc" cookieless="false" />
  </system.web>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
    </staticContent>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <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="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
 <appSettings configSource="AppSettings.config" />
<system.net>
  <mailSettings>
    <smtp from="thenna4@gmail.com">
      <network host="smtp-mail.outlook.com" 
               port="587" 
               userName="thenna41@gmail.com"
               password="pixel@1990" 
               enableSsl="true" />
    </smtp>
  </mailSettings>
</system.net>
</configuration>

哪有错误任何人帮助我?提前谢谢

0 个答案:

没有答案