This documentation is archived and is not being maintained.

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)

type SqlProfileProvider =  
        inherit ProfileProvider

The SqlProfileProvider type exposes the following members.

Public methodSqlProfileProviderCreates an instance of the SqlProfileProvider class.

Public propertyApplicationNameGets or sets the name of the application for which to store and retrieve profile information. (Overrides SettingsProvider.ApplicationName.)
Public propertyDescriptionGets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs). (Inherited from ProviderBase.)
Public propertyNameGets the friendly name used to refer to the provider during configuration. (Inherited from ProviderBase.)

Public methodDeleteInactiveProfilesDeletes user profile data for profiles in which the last activity date occurred before the specified date and time. (Overrides ProfileProvider.DeleteInactiveProfiles(ProfileAuthenticationOption, DateTime).)
Public methodDeleteProfiles(ProfileInfoCollection)Deletes profile properties and information for the supplied list of profiles from the data source. (Overrides ProfileProvider.DeleteProfiles(ProfileInfoCollection).)
Public methodDeleteProfiles(String[])Deletes profile properties and information from the data source for the supplied list of user names. (Overrides ProfileProvider.DeleteProfiles(String[]).)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFindInactiveProfilesByUserNameRetrieves profile information for profiles in which the last activity date occurred on or before the specified date and time and the user name for the profile matches the specified name. (Overrides ProfileProvider.FindInactiveProfilesByUserName(ProfileAuthenticationOption, String, DateTime, Int32, Int32, Int32).)
Public methodFindProfilesByUserNameRetrieves profile information for profiles in which the user name matches the specified name. (Overrides ProfileProvider.FindProfilesByUserName(ProfileAuthenticationOption, String, Int32, Int32, Int32).)
Public methodGetAllInactiveProfilesRetrieves user profile data for profiles in which the last activity date occurred on or before the specified date and time. (Overrides ProfileProvider.GetAllInactiveProfiles(ProfileAuthenticationOption, DateTime, Int32, Int32, Int32).)
Public methodGetAllProfilesRetrieves user profile data for profiles in the data source. (Overrides ProfileProvider.GetAllProfiles(ProfileAuthenticationOption, Int32, Int32, Int32).)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetNumberOfInactiveProfilesGets the number of profiles in the data source where the last activity date occurred on or before the specified userInactiveSinceDate. (Overrides ProfileProvider.GetNumberOfInactiveProfiles(ProfileAuthenticationOption, DateTime).)
Public methodGetPropertyValuesRetrieves profile property information and values from a SQL Server profile database. (Overrides SettingsProvider.GetPropertyValues(SettingsContext, SettingsPropertyCollection).)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeInitializes the SQL Server profile provider with the property values specified in the ASP.NET application's configuration file. This method is not intended to be used directly from your code. (Overrides ProviderBase.Initialize(String, NameValueCollection).)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSetPropertyValuesUpdates the SQL Server profile database with the specified property values. (Overrides SettingsProvider.SetPropertyValues(SettingsContext, SettingsPropertyValueCollection).)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

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\2.0versionNumber folder, and specify the -A p option. The following command demonstrates how you might use the aspnet_regsql.exe executable:

aspnet_regsql.exe -A p

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.


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.

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

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

    <authentication mode="Forms" >
      <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH" />
      <deny users="?" />
    <membership defaultProvider="SqlProvider" 
        <add name="SqlProvider" 
          requiresQuestionAndAnswer="true" />

    <profile defaultProvider="SqlProvider">
        <clear />
        <add name="SqlProvider"
          description="SqlProfileProvider for SampleApplication" />

        <add name="ZipCode" />
        <add name="CityAndState" />

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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