更新web.config以将aspnetdb更改为自己的数据库?

时间:2012-04-15 08:17:27

标签: c# sql-server wcf-ria-services aspnetdb

我正在开发一个Web应用程序,我必须添加一些授权,所以我有一个数据库ASPNETDB.MDF,我希望我的应用程序使用SQL Server中的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文件中进行哪些更改。

由于

回复

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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>