SqlProfileProvider Class
Manages storage of profile information for an ASP.NET application in a SQL Server database.

Namespace: System.Web.Profile
Assembly: System.Web (in system.web.dll)
Syntax

Visual Basic (Declaration)
Public Class SqlProfileProvider
    Inherits ProfileProvider
Visual Basic (Usage)
Dim instance As SqlProfileProvider
C#
public class SqlProfileProvider : ProfileProvider
C++
public ref class SqlProfileProvider : public ProfileProvider
J#
public class SqlProfileProvider extends ProfileProvider
JScript
public class SqlProfileProvider extends ProfileProvider
XAML
Not applicable.
Remarks

The ASP.NET profile is used to store and retrieve user settings in a data source such as a database. The user profile is accessed using the Profile property of the current HttpContext. Profile information and property values are managed using a profile provider.

The SqlProfileProvider class is used by ASP.NET to store and retrieve profile settings for an ASP.NET application that is using a SQL Server database. To use a SqlProfileProvider, you must first create the SQL Server database used by the SqlProfileProvider. To create the database used by the SqlProfileProvider, run the aspnet_regsql.exe tool, which is found in the [drive:]\WINDOWS\Microsoft.NET\Framework\versionNumber folder, and specify the -Ap option. The following command demonstrates how you might use the aspnet_regsql.exe executable:

aspnet_regsql.exe -Ap

The example above does not specify a name for the database that is created, so the default name will be used. The default database name is Aspnetdb.

The machine configuration contains a default SqlProfileProvider instance named AspNetSqlProvider that connects to the SQL Server on the local machine. You can use this instance of the provider, or specify your own in the Web.config file for your ASP.NET application.

NoteNote:

If the profile provider is configured with a connection string that uses integrated security, the process account of the ASP.NET application must have rights to connect to the SQL Server database.

Example

The following code example shows the Web.config file for an ASP.NET application configured to use a SqlProfileProvider.

<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString=
      "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
  </connectionStrings>

  <system.web>
    <authentication mode="Forms" >
      <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
    <membership defaultProvider="SqlProvider" 
      userIsOnlineTimeWindow="15">
      <providers>
        <clear/>
        <add name="SqlProvider" 
          type="System.Web.Security.SqlMembershipProvider" 
          connectionStringName="SqlServices"
          applicationName="SampleApplication"
          enablePasswordRetrieval="true"
          enablePasswordReset="true"
          passwordFormat="Encrypted"
          requiresQuestionAndAnswer="true" />
      </providers>
    </membership>

    <profile defaultProvider="SqlProvider">
      <providers>
        <clear />
        <add name="SqlProvider"
          type="System.Web.Profile.SqlProfileProvider"
          connectionStringName="SqlServices"
          applicationName="SampleApplication"
          description="SqlProfileProvider for SampleApplication" />
      </providers>

      <properties>
        <add name="ZipCode" />
        <add name="CityAndState" />
      </properties>
    </profile>
  </system.web>
</configuration>
.NET Framework Security

Inheritance Hierarchy

System.Object
   System.Configuration.Provider.ProviderBase
     System.Configuration.SettingsProvider
       System.Web.Profile.ProfileProvider
        System.Web.Profile.SqlProfileProvider
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Version Information

.NET Framework

Supported in: 3.0, 2.0
See Also

Tags :


Page view tracker