One of the products I work with daily is Commerce Server 2000 and 2002 from Microsoft which is an interesting product trying to create a standard e-commerce platform on which you can develop your own solutions.
Anyway the product is very complex and has all kinds of nooks and crannies due to the fact that version 2000 was an ASP only product. Version 2002 has a lot of .NET classes and stuff to use but it is still just a layer added to the top of the COM objects found in version 2000.
I was tasked with creating a program which does some bulk updating using the Commerce objects. One of the tricks in Commerce Server is that it comes with a built in data abstraction layer called the profile system. A profile in the profile system is basically a table in SQL Server.
Back to the task at hand; I needed to create a ProfileContext outside of ASP.NET where it is available through a HTTP handler so I needed to figure out how to get at it without the HTTP handler doing the "heavy lifting".
First you need to add a couple of references to the COM based DLLs named ADODB.dll, AppHelper.dll, and MSCSCFG.dll. They are all found in your Commerce directory. Finally you need the managed Commerce Server runtime DLL named Microsoft.CommerceServer.Runtime.dll which is found in the Commerce Server\Assemblies directory.
Now for some code: First I needed to get the connection string for the profile system which I did in the following way:
// Get the profile connection string from the system config
AppConfig appConfig = new AppConfigClass();
appConfig.Initialize( ConfigurationSettings.AppSettings[ "name of your commerce application" ] );
Microsoft.CommerceServer.Runtime.IDictionary configDictionary = appConfig.GetOptionsDictionary( "" );
string profileConnectionstring = Convert.ToString( configDictionary[ "s_ProfileServiceConnectionString" );
// Instantiate the ProfileContext object
string profileDefinitionCatalog = "Profile Definitions"; // You can look this value up in the Commerce Manager
ProfileContext profileContext ProfileContext( connectionString, profileDefinitionCatalog, new ConsoleDebugContext( DebugMode.Production ) );