How to Create Code for Profile Refresh in Visual C# .NET (815700)



The information in this article applies to:

  • Microsoft Commerce Server 2002

For a Microsoft Visual Basic .NET version of this article, see 816081.

SUMMARY

When you create a new Commerce Server Microsoft ASP.NET Web application in Microsoft Visual C# .NET by using Microsoft Visual Studio .NET, the code that is generated does not contain all the code that is required for profile refresh to function correctly. Also, the documentation does not contain the information that you must have to write this code.

MORE INFORMATION

In the source code of the RefreshApp.aspx (RefreshApp.aspx.cs) file, the code that is generated causes a profile refresh to fail. The following is the default code:
private void ProfileRefresh()
{
		// Implement Profile Service Refresh here
		// Please see the Profile Service documentation for more information on
		// implementing a refresh of the Profile Service

		// This will cause "Publish failed" to appear in the Business Desk application status
		throw new Exception("Publish failed");
}
If you use the default profile system, you can replace the default code with the following code to provide valid profile refresh functionality. To do this, follow these steps:
  1. Add the following references to the code:
    	using Microsoft.CommerceServer.Runtime;
    	using Microsoft.CommerceServer.Runtime.Profiles;
  2. Replace the existing code with the following sample code:
    private void ProfileRefresh()
    {
    	ProfileContext profContext = CommerceContext.Current.ProfileSystem;
    	string bdaoConnectionString;
    	string providerConnectionString;
    	string profilesConnectionString;
    	bdaoConnectionString = (string)CommerceApplicationModule.Resources["Biz Data Service"]["s_BizDataStoreConnectionString"].ToString();
    	providerConnectionString = (string)CommerceApplicationModule.Resources["Biz Data Service"]["s_CommerceProviderConnectionString"].ToString();
    	profilesConnectionString = (string)CommerceApplicationModule.Resources["Biz Data Service"]["s_ProfileServiceConnectionString"].ToString();
    	profContext = new ProfileContext(profilesConnectionString, providerConnectionString, bdaoConnectionString, CommerceContext.Current.DebugContext);
    	CommerceProfileModule.ProfileContext = profContext;
    }

Modification Type:MajorLast Reviewed:9/2/2003
Keywords:kbhowto KB815700 kbAudDeveloper