0

我正在开发一个 Web 应用程序,我必须在其中添加一些授权,所以我确实有一个数据库 ASPNETDB.MDF,我希望我的应用程序使用来自 SQL 服务器的 WATERINFO.MDF。

我已经使用 aspnet_regsql.exe 用所有模式和数据更新了 WATERINFO.MDF

目前我的silverlight应用程序的web.config文件是

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="system.serviceModel">
      <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web>
    <httpModules>
      <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </httpModules>
    <compilation debug="true" targetFramework="4.0" />

    <roleManager enabled="true"/>

    <authentication mode="Forms">
      <forms name=".AuthorizationSample_ASPXAUTH" />
    </authentication>

    <profile>
      <properties>
        <add name="FriendlyName"/>
      </properties>
    </profile>

  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="DomainServiceModule" preCondition="managedHandler"
          type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </modules>
  </system.webServer>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>

现在要将其更改为 WATERINFO.MDF 我需要更新配置文件

      <?xml version="1.0"?>
    <configuration>
<connectionStrings>
        <add name="DefaultConnectionString" connectionString="Data Source=COMPLEX\SQLEXPRESS;Initial Catalog=waterinfo;Integrated Security=True"
    providerName="System.Data.SqlClient" />

      </connectionStrings>
      <configSections>
        <sectionGroup name="system.serviceModel">
          <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" />
        </sectionGroup>
      </configSections>



      <system.web>

        <roleManager enabled="true" defaultProvider="DPISqlRoleProvider">
          <providers>
            <add connectionStringName="DefaultConnectionString" applicationName="DPI" name="DPISqlRoleProvider"
     type="System.Web.Security.SqlRoleProvider"/>

          </providers>
        </roleManager>
        <httpModules>
          <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </httpModules>
        <compilation debug="true" targetFramework="4.0" />



        <authentication mode="Forms">

        </authentication>


        <membership defaultProvider="DPISqlMembershipProvider">

          <providers>
            <add connectionStringName="DefaultConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true"
     requiresQuestionAndAnswer="true" applicationName="DPI" requiresUniqueEmail="true" passwordFormat="Hashed"
     maxInvalidPasswordAttempts="5" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0"
     passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="DPISqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"/>

          </providers>
        </membership>
        <profile>
          <properties>
            <add name="FriendlyName"/>
          </properties>
        </profile>

      </system.web>

      <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true">
          <add name="DomainServiceModule" preCondition="managedHandler"
              type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </modules>
      </system.webServer>

      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    </configuration>

我在 web.config 文件中更新了这些更改,但无法将数据库更改为新数据库。

我也知道我可以使用<remove "LocalSqlServer">,但现在这对生产目的有好处

请建议我应该在我的 web.config 文件中进行哪些更改。

谢谢

回复

4

2 回答 2

0

您需要将 connectionStrings 标记放在 configSections 下方。configSections 必须是第一个,如msdn中所述。

于 2012-04-15T08:48:58.050 回答
0

我解决了这个问题,有一些连接字符串错误和其他一些分钟更改......我需要更新 Web.Config 文件

 <?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="system.serviceModel">
      <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <connectionStrings>
    <add name="DefaultConnectionString" connectionString="My Connection Details"
providerName="System.Data.SqlClient" />

  </connectionStrings>


  <system.web>

    <roleManager enabled="true" defaultProvider="DPISqlRoleProvider">
      <providers>
        <add connectionStringName="DefaultConnectionString" applicationName="DPI" name="DPISqlRoleProvider"
 type="System.Web.Security.SqlRoleProvider"/>

      </providers>
    </roleManager>
    <httpModules>
      <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </httpModules>
    <compilation debug="true" targetFramework="4.0" />



    <authentication mode="Forms">

    </authentication>


    <membership defaultProvider="DPISqlMembershipProvider">

      <providers>
        <add connectionStringName="DefaultConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true"
 requiresQuestionAndAnswer="true" applicationName="DPI" requiresUniqueEmail="true" passwordFormat="Hashed"
 maxInvalidPasswordAttempts="5" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0"
 passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="DPISqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"/>

      </providers>
    </membership>
    <profile>
      <properties>
        <add name="FriendlyName"/>
      </properties>
    </profile>

  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="DomainServiceModule" preCondition="managedHandler"
          type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </modules>
  </system.webServer>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>
于 2012-04-15T18:19:06.890 回答