Using Web Parts with SQL Server 2000/2005.
Configuring application services in your asp.net application is a two step process:
1. Configure database objects that will hold application services data.
2. Configure providers that will provide access to application services data from the database.
For Configure database objects use following sql script that will create database & its objects(tables, Sps) for storing application services objects.
These are found at
InstallCommon.sql
InstallMembership.sql
InstallPersonalization.sql
InstallProfile.sql
InstallRoles.sql
Make sure you run "InstallCommon.sql" script first as it creates database before running other scripts. By default database name is "aspnetdb" but if you want to change it, you can update InstallCommon.sql script.
These sql scripts are handy if you dont want to use all application services or you dont want to create separate database for it. In that case you can run any one or all script(s) depending upon the service you want to use on your application database. like if you want to implement only personalization then you just need to run "InstallPersonalization.sql" on your main database.
You can unstall these objects as well using following sql scripts.
UninstallCommon.sql
UninstallMembership.sql
UninstallPersonalization.sql
UninstallProfile.sql
UninstallRoles.sql
For example you may want to use only personization service not profile, membership and role service in that case there is no point to have other services configured in the application.
So you can run InstallCommon.sql followed by InstallProfile.sql sql scripts.
Note:- dont forget to change database name in the InstallCommon.sql sql script with the database in which you want to configure application service data objects.
You can do same thing using aspnet_regsql.exe utility as well using following command at the command prompt.
aspnet_regsql.exe -S < server name > -U < username > -P < password > -A < service code > -d < database name >
service code - all : all services
m : membership
r : role manager
p : profile
c : personalization
w : sql web event provider
For example if you have to add only profile service in your existing database, run following command at the command prompt:
aspnet_regsql.exe -S myserver -U user1 -P pass1 -A p -d mydb
Note:- replace server name, user name, password and database name with user's.
To remove profile service use -R in place of -A
Like:- aspnet_regsql.exe -S myserver -U user1 -P pass1 -R p -d mydb
----------------------------------------------------------
Second step is to configure providers in the web application.
Below is the code sample that can be added in the web.config file depending upon the application service you want to configure in your web application.
Provider's configuration in web.config file.
< !-- Connection string will point to the database that is configured to store application service data -- >
< connectionStrings >
< add name="SQLConnString" connectionString="Data Source=FN-WS282-D8;Initial Catalog=AppServices;Integrated Security=false; user id=sa; pwd=pass1" providerName="System.Data.SqlClient" />
< /connectionStrings >
< !-- Add following code for configuring personalization in the web.config file -- >
< webParts >
< personalization defaultProvider="SqlPersonalizationProvider" >
< providers >
< add name="SqlPersonalizationProvider" type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" connectionStringName="SQLConnString" applicationName="/" />
< /providers >
< authorization >
< deny users="*" verbs="enterSharedScope" />
< allow users="*" verbs="modifyState" />
< /authorization >
< /personalization >
< /webParts >
< !-- Add following code for configuring profile in the web.config file -- >
< profile defaultProvider="SqlProfileProvider" >
< providers >
< clear />
< add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="SQLConnString" applicationName="/" />
< /providers >
< properties >
< add name="Message" type="System.String" />
< /properties >
< /profile >
< !-- Add following code for configuring membership in the web.config file -- >
< membership defaultProvider="SqlMembershipProvider" >
< providers >
< clear />
< add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="SQLConnString" applicationName="/" />
< /providers >
< /membership >
< !-- Add following code for configuring role manager in the web.config file -- >
< roleManager defaultProvider="SqlRoleProvider" >
< providers >
< clear />
< add name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="SQLConnString" applicationName="/" />
< /providers >
< /roleManager >
No comments:
Post a Comment