The essence of the article is to enable the use of Enterprise Application Block with BizTalk Server 2006 development. Using the Enterprise Application Block in web applications or windows based applications is eased by the use of web.config or app.config respectively. However as the BizTalk server runs as a service on the server the configuration of the application using a app.config is not suitable and does not work.
Being expert .NET Developer, I always wanted to use my expertise in .NET Coding to facilitate the development of maps by using the scripting functoid. The Helper Project developed for this purpose consumed the Data Access Library Project created for a previous project and heavily depended on the Enterprise Application blocks for fetching Data from the database and logging exceptions. However the Data Access Application block kept throwing exceptions in the Event Viewer as BizTalk Exceptions indicating the configuration was incorrect and Logging Application Block never worked.
In my approach to Solution Oriented Approach, the simplest solution to a problem is mapping it to a problem whose solution we already know.
Mapping it to a Known Problem:
When you want to use Enterprise Application blocks with a ASP.NET web application we are recommended to open the web.config in the Enterprise Application Block configuration tool. Similarly since BizTalk Components run inside BizTalk Service BTSNTSVC.exe we can do the configuration of the Data Access Application Block and Logging application block in the BTSNTSVC.exe.config file.
 The BTSNTSVC.exe.config file is found at Program Files/Microsoft Biztalk Server 2006 folder on your machine.
However unlike the web.config we do not want to clutter the BTSNTSVC.exe.config file with the Configuration Information for the application blocks. The recommended usage is the use of external application configuration files and creating entries in the BizTalk Configuration file to point to these config entries.
Enterprise Application Block Components to Use:
- Configuration Sources Application Block à File Configuration Source
- Application Settings – File Source
- Data Access Application Block
Outlining the Step by Step Approach:
- Lets open the File in a Enterprise Application Configuration. Click Start - All Programs -Microsoft Patterns and Practices - Library 3.1 - Library Configuration
- File à Open Application à BTSNTSVC.exe.config
(Note: Please back up the file so that you do not mess the configuration in case something goes south)
Here is how a typical BTSNTSVC.EXE.CONFIG file looks in the Enterprise Configuration Wizard:
- Right click on the C:\Program Files .. and click new Configuration Sources.
- Select file configuration source and select a Configuration File say Config.xml
- Now close the application and open the Config.xml file and configure the Data Access Application block by creating Connection Strings and default databases. Save the configuration and close the application.
- Now reopen the BTSNTSVC.exe.config file and check out the Enterprise Data Access Application configuration created in the database. Now right click the Application Settings and select an external file for storing the application settings entries. (you might have created this file already using the app.config file)
- Once the application settings file and Data Access Application Configuration is complete the BTSNTSVC.Exe.config file will look like this in the Enterprise Configuration Application
However before you are ready to start writing code in your Helper projects BTSNTSVC.exe needs to be notified about the change in the Config file and hence using the BizTalk Administration make sure you restart the service.
The Enterprise Application Block is now ready to use in the BizTalk Application. Now in your helper classes you can do database connection using the
Database db = DatabaseFactory.CreateDatabase(“MyDB”);
OR You can log using