3

我在将 ASP.NET 的默认成员连接字符串更改为远程连接字符串时遇到问题。这是我尝试使用的连接字符串:

Data Source=myserver.com;Integrated Security=True;Initial Catalog=database_name;User ID=username;Password=password

该数据库托管在共享主机上,并且可以通过 SQL Server Management Studio 访问,我还使用记事本方法测试了完全相同的连接字符串等等......

所以,我几乎可以肯定问题不是我的连接字符串,而是web.config. 这是web.config文件:

http://pastebin.com/JsATXqW7

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <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>
    <httpRuntime targetFramework="4.5" requestValidationMode="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    <machineKey compatibilityMode="Framework45" />
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership>
      <providers>
        <add connectionStringName="RemoteDB" enablePasswordRetrieval="false"
          enablePasswordReset="true" requiresQuestionAndAnswer="false"
          requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
          minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
          applicationName="/" name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </providers>
    </membership>
    <roleManager>
      <providers>
        <add connectionStringName="RemoteDB" applicationName="/"
          name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </providers>
    </roleManager>
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="RemoteDB" />
      </providers>
    </sessionState>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
  </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>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-SkypeSpammerWeb-20121018205959;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-SkypeSpammerWeb-20121018205959.mdf" />
    <add name="RemoteDB" providerName="System.Data.SqlClient" connectionString="Data Source=xxxxxxx.com;Integrated Security=True;Initial Catalog=xxxxxx;User ID=xxxxxx;Password=xxxxxxxx"/>
  </connectionStrings>
</configuration>

这是我收到的错误的屏幕截图:

http://postimage.org/image/3vd3dbahf/

4

2 回答 2

0

您需要更改为:

<membership defaultProvider="DefaultMembershipProvider">
    <providers>
        <clear/>
        <add ...

我还注意到您的连接字符串有Data Source=xxxxxxx.com,我假设您只是将其阻止发布,但它真的以 .com 结尾吗?您确定完全限定的 .com 地址可以从您的 Web 服务器解析吗?

于 2012-10-18T23:01:17.770 回答
0

我认为您应该删除“Integrated Security=True”,我认为共享主机不会使用您的 Windows 帐户和密码。

于 2012-10-19T05:18:20.277 回答