Migrating ASP.NET applications to another Windows Domain

You may have to migrate Intranet software applications to another Windows Domain (e.g. Due to company restructure). As Intranet applications normally uses Domain account to authorize user access, changing domain means you have to change user group settings, sometimes source code and sometimes even worse your third-party applications will not work properly -- e.g. old data uses old domain account so that user cannot change their data using new domain account.

If your applications were based on ASP.NET framework, then there is a simple solution to ease the pain at least temporarily: you keep all those ASP.NET applications in original domain and add a HttpModule (defined in web.config) to map new domain account to old domain account. When users in new domain access those applications in old domain, the ASP.NET application will only see the old domain account so the users still work in the exact same way as before.


The main code logic for domain mapping HttpModule is as below:

// Get user's domain account
string strDomainUserAccount = HttpContext.Current.User.Identity.Name.ToUpper();

// Remove domain name from the account
string strUserAccount = strDomainUserAccount;
if (strDomainUserAccount.StartsWith("NewDomain\\")) {
 strUserAccount = strUserAccount.Substring(10);
}

// Fetch cached user mappings
Dictionary userMap = (Dictionary)HttpRuntime.Cache(USER_CACHE_KEY);
if (userMap == null) {
 // If no cache is available, reload the cache from database 
 // and try to get the item again
 this.ReloadUserMap();
 
 userMap = (Dictionary)HttpRuntime.Cache(USER_CACHE_KEY);
 if (userMap == null) {
  // Throw exception here!!
  return;
 }
}

// Get user's NTUserName from the mapping in cache 
// and create a new user for Http context
if (userMap.ContainsKey(strUserAccount)) {
 string strNewAccount = userMap[strUserAccount];
 
 if (!string.IsNullOrEmpty(strNewAccount)) {
  // New Identity
  string strAuthenticateType = HttpContext.Current.User.Identity.AuthenticationType;
  System.Security.Principal.GenericIdentity newID = 
   new System.Security.Principal.GenericIdentity(strNewAccount, strAuthenticateType);
  
  // Get cached roles in mapped domain. 
  // If no cache is available, get from AD and put into cache
  string[] strRoles = this.GetDomainGroupsForUserFromCache[strNewAccount];
  System.Security.Principal.GenericPrincipal newP = 
   new System.Security.Principal.GenericPrincipal(newID, strRoles);
  
  HttpContext.Current.User = newP;
 }
}

FlowLayoutPanel for .NET Compact Framework

It is quite complex to arrange Windows Form layout dynamically in .NET Compact Framework (CF) when you try to show/hide a control between other controls. Although you can use FlowLayoutPanel in desktop Windows Form application, there is no such kind of layout manager for CF.

I found an old article on CodeProject about FlowLayoutPanel, but that code cannot work on CF because CF Panel does not have OnLayout event. Also the code logic has bugs too.

After searching for a while, I decided to make a FlowLayoutPanel for CF by myself. It turns out the code is not hard to write:

Protected Overloads Overrides Sub OnPaint(ByVal pEvent As PaintEventArgs)
 Dim nextTop As Integer = 0, nextLeft As Integer = 0
 Dim maxHeight As Integer = 0
 Dim ParentWidth As Integer
 
 If Me.Parent IsNot Nothing Then
  ParentWidth = Me.Parent.Width
 Else
  ParentWidth = Me.Width
 End If

 ' Modify control location for the layout
 For Each myControl As Control In Me.Controls
  ' Ignore invisible controls
  If myControl.Visible = False Then
   Continue For
  End If

  If (nextLeft + myControl.Width) > ParentWidth Then
   nextTop += maxHeight
   nextLeft = 0
   ' Reset maxHeight
   maxHeight = 0
  End If

  myControl.Top = nextTop
  myControl.Left = nextLeft

  If myControl.Height > maxHeight Then
   maxHeight = myControl.Height
  End If

  nextLeft += myControl.Width
 Next
 Me.AutoScrollPosition = New System.Drawing.Point(0, 0)

 MyBase.OnPaint(pEvent)
End Sub

Below is a sample using the logic above:


To make layout easier, I put several panels inside the FlowLayoutPanel. You can see all the controls are arranged properly. When I click the "Hide Panel 3" button, the Form becomes this:


The controls below Panel 3 are moved up automatically. If I click "Show Panel 3" button, the Panel 3 will be displayed at original place and all the controls below it are moved down accordingly.

The code for the button is like below:

Private Sub btnHide_Click(ByVal sender As Object, ByVal e As EventArgs)
 If btnHide.Text = "Hide Panel 3" Then
  Panel3.Visible = False
  btnHide.Text = "Show Panel 3"
 Else
  Panel3.Visible = True
  btnHide.Text = "Hide Panel 3"
 End If

 ' Refresh the flow layout panel
 Me.FlowLayoutPanel1.Invalidate()
End Sub

There is a small problem in Visual Studio though: when you drag-drop a control to the FlowLayoutPanel, Visual Studio always puts the control as the first one inside the FlowLayoutPanel. You need to modify the designer file to manually put those controls in order:

'FlowLayoutPanel1
'
Me.FlowLayoutPanel1.Controls.Add(Me.Panel1)
Me.FlowLayoutPanel1.Controls.Add(Me.Panel2)
Me.FlowLayoutPanel1.Controls.Add(Me.Panel3)
Me.FlowLayoutPanel1.Controls.Add(Me.Panel5)
Me.FlowLayoutPanel1.Controls.Add(Me.Panel6)
Me.FlowLayoutPanel1.Controls.Add(Me.Panel4)

Set up Reporting Services in SharePoint Integration Mode

I followed How to: Configure SharePoint Integration on Multiple Servers step-by-step to configure SharePoint Integration on two servers. But on the step "Set server defaults" of "Configure the Report Server Integration Feature in SharePoint Central Administration", I only saw this error:

An unexpected error occurred while connecting to the report server. Verify that the report server is available and configured for SharePoint integrated mode.

I was sure I followed the steps carefully. Then I tried to look for error details in Web and Database log files, but there was no any error message. After many hours of investigation, I found somebody mentioned Kerberos/NTLM on MSDN Forum. As my environment did not allow me to use Kerberos, I tried to set up NTLM on both SharePoint server and Report server:

cscript adsutil.vbs set w3svc/NTAuthenticationProviders "NTLM"

Then I was so happy to see the error disappeared! :)

SSAS Permission for Least-Privilege User Account

When using LUA (Least-Privilege User Account) on development machine, I normally add myself as sysadmin for SQL server, so that I can create database freely.

As SSAS is part of SQL Server, I took it for granted that my account was also sysadmin in SSAS. But it turned out that SSAS has different permission settings from SQL Server.

When I tried to deploy an SSAS project, Visual Studio threw the error:

Error -1055391738 : Either the '[domain]\[account]' user does not have permission to create a new object in '[machine]', or the object does not exist.

So I went to SQL Server Management Studio and connected to SSAS, but I had no permission to create SSAS database manually:

Either the '[domain]\[account]' user does not have permission to create a new object in '[machine]', or the object does not exist. (Microsoft.AnalysisServices)


One way to solve the problem is to add my account to the SSAS' server role, which means to grant server-wide security privileges to my account in SSAS:
  1. Run SQL Server Management Studio as Administrator account
  2. Connect to the SSAS server
  3. Right-click the SSAS server name and select Properties from the popup menu
  4. Select Security to add account to server role

Now, I can deploy SSAS project in Visual Studio without problem.

SharePoint can not find user in its domain

It's quite weird that SharePoint (WSS 3.0) could not find any Active Directory user account from its own domain!

According to its log, WSS complained it could not get trusted domains:

05/08/2008 10:09:18.72  Error when trying to get trusted forests and domains. Exception message: Access is denied.  , callstack:    at System.DirectoryServices.ActiveDirectory.Forest.GetTrustsHelper(String targetForestName)     at System.DirectoryServices.ActiveDirectory.Forest.GetAllTrustRelationships()     at Microsoft.SharePoint.Utilities.SPUserUtility.GetTrustedDomains(List`1 trustedForestNames, List`1 trustedDomainNames)  
05/08/2008 10:09:18.72 Found 1 trusted forests ad.int.com.
05/08/2008 10:09:18.72 Found 0 trusted domains
05/08/2008 10:09:18.87 Error in searching user 'Bob' : System.DirectoryServices.DirectoryServicesCOMException (0x8007052E): Logon failure: unknown user name or bad password. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_AdsObject() at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) at System.DirectoryServices.DirectorySearcher.FindAll() at Microsoft.SharePoint.WebControls.PeopleEditor.SearchFromGC(SPActiveDirectoryDomain domain, String strFilter, String[] rgstrProp, Int32 nTimeout, Int32 nSizeLimit, SPUserCollection spUsers, ArrayList& rgResults) at Microsoft.SharePoint.Utilities.SPUserUtility.SearchAgainstAD(String input, SPActiveDirect...
05/08/2008 10:09:18.87* ...oryDomain domainController, SPPrincipalType scopes, SPUserCollection usersContainer, Int32 maxCount, String customQuery, String customFilter, TimeSpan searchTimeout, Boolean& reachMaxCount) at Microsoft.SharePoint.Utilities.SPActiveDirectoryPrincipalResolver.SearchPrincipals(String input, SPPrincipalType scopes, SPPrincipalSource sources, SPUserCollection usersContainer, Int32 maxCount, Boolean& reachMaxCount) at Microsoft.SharePoint.Utilities.SPUtility.SearchPrincipalFromResolvers(List`1 resolvers, String input, SPPrincipalType scopes, SPPrincipalSource sources, SPUserCollection usersContainer, Int32 maxCount, Boolean& reachMaxCount, Dictionary`2 usersDict).


But do I need care if the domain is "trusted" or not when only one domain exists? What I wanted was to get users from the same domain. MSDN also said "Users in the forest that the server is in (that is, a resource forest) are displayed automatically." But the reality was the opposite.

Finally, I had a try to add the WSS server's local domain using stsadm:

stsadm -o setproperty -url http://localhost:82
-pn "peoplepicker-searchadforests" -pv "domain:ad.int.com"

Although I had thought that the command should do nothing because I was not supposed to do that, ironically I could see users in the PeoplePicker control! :)

SharePoint XML Web Part and proxy setting

XML Web Part is quite useful when you want to collect data from other sites (e.g. RSS). Yesterday I wanted to display local weather information using Weather.com XML Data Feed. I followed these steps:
  1. Registered to weather.com to download the SDK (to use weather images)
  2. Copied SDK images to TEMPLATE\Images\weather\
  3. Added XML Web Part to WSS site and set URL to
    http://xoap.weather.com/weather/local/(zipcode)?cc=*&prod=xoap
    &unit=e&par=null&key=(license key)
    [Update] Weather.com has changed the URL to
    http://xoap.weather.com/weather/local/[zipcode]?cc=*&dayf=5
    &link=xoap&prod=xoap&par=[PartnerID]&key=[LicenseKey]
  4. Set up XSLT to display weather images
But I got errors on different WSS machines:
  1. "Cannot retrieve the URL specified in the XML Link property"
  2. "The web part has timed out"
The reason was my WSS sites were behind a proxy server. WSS XML Web Part need know proxy settings, otherwise it can not access the URL.

The first error happens when the WSS application pool does not use a domain account; the second error happens when a domain account is used.

After I added proxy settings in web.config, the problem was solved:

<!-- Proxy setting -->
<system.net>
<defaultproxy useDefaultCredentials="true">
<proxy usesystemdefault="false"
proxyaddress="http://proxyServer:port"
bypassonlocal="true">
</proxy>
</defaultproxy>
</system.net>

ZoomIt

This post is mainly for my own recall.

Robert Shelton provides a link for the excellent screen zoom and annotation tool for Windows. It is quite useful for presentation of course, but also useful to zoom in/out high resolution screen during normal work.

I tried on my computer just now:

Reports cannot be deployed from VS 2005 to Reporting Services in WSS integration mode

I tried to deploy reports from VS 2005 from Dev machine to Prod Report Server across different domains, but VS 2005 did not allow me to deploy.

The Reporting Services on Prod was set up in WSS integration mode. I set up TargetDataSourceFolder, TargetReportFolder and TargetServerURL in VS 2005 on my Dev machine as mentioned in MSDN article "Deploying Reports, Models, and Shared Data Sources to a SharePoint Site". Then I tried to deploy reports to Prod machine. But VS 2005 keeps showing "Report Services Login" window, even when I used Administrator account of Prod.

The WSS log file on the Prod machine shows this error: "The file you are attempting to save or retrieve has been blocked from this Web site by the server administrators."

Solution? After two-day frustration and research, then the problem was solved: I need use Internet Explorer to log into WSS and check the "Remember my password" checkbox (Very important!). Then I could deploy from VS 2005 without seeing the login dialog window. The deployed report on Prod showed the author was the same account that I used to login from IE.

The same trick can be applied to Report Builder. When user tries to use Report Builder in WSS to build ad-hoc report, he/she should make sure to check the "Remember my password" checkbox in the login window. Otherwise, the user will see "unauthorized" error when downloading Report Builder application.

Do not remove VS 2005 and install VS 2008 if ...

Do not remove VS 2005 from your computer and install VS 2008 if:

1. You want to develop Business Intelligence solutions with SQL Server 2005, because VS 2008 does not support those projects (Report Designer, Report Model ...). Or to say, Microsoft does not want you to work on SQL Server 2005 with their own latest IDE!

2. You want to build Workflow (WF) solution for SharePoint. You will realize the old way in VS 2005 to install Features.xml is easier to use.

WSS Workflow Modification Form

It is easy to find WSS ASP.NET samples for Instantiation and Task Edit forms, but it is hard to find sample for Modification form. Maybe many people think there is no much difference, but is that true?

Modification form is quite useful in WSS work flow. For example, after a long running task has been assigned to an analyst, the analyst takes vacation for weeks. At this point, the Modification form can be used to reassign the task to another person.

You can define Modification form in Feature file with the similar way for Instantiation form. But how about the workflow part?

Instantiation form happens at the very beginning of a workflow, but Modification can happen anywhere in a scope.

A common way to define Modification in workflow is to put EnableWorkflowModification activity inside an EventHandlingScope activity. Other activities inside the same scope do the normal work. When Modification form is accessed, an event will raised to the workflow, so that the EventHandlingScope activity can handle the event and call event handler.

In Visual Studio, right-click the EventHandlingScope activity and select "view event handlers":


Then you can add OnWorkflowModified and UpdateTask activities to the EventHandlersActivity:



The Modification activities have their own ContextData and CorrelationToken, because they are actually outside the normal workflow.

One issue I saw: If there is an OnTaskChanged activity already defined in the EventHandlingScope (like below), you had better not add another OnTaskChanged activity inside the EventHandlersActivity; otherwise, you would be surprised to see only one OnTaskChanged activity is called.

WSS Content Type Was Not Updated

I tried to update a content type in WSS, but the system was still using the older version of content type somehow. After two-day frustration, I found out why :(

Here was what happened in the beginning: I created a simple content type like below:

<ContentType ID="0x01080100B7336179CFFE43e59B86E241C767010E" Name="GradingTask" Group="Grading" Description="Grading Task" Version="0" Hidden="FALSE">
</ContentType>


The content type worked perfectly and I added several items of GradingTask type to a list. Then I thought: How about adding custom Edit/Display pages? So I added these lines to the configuration:

<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
<FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
<Edit>_layouts/Grades/GradesTaskEditForm.aspx</Edit>
<Display>_layouts/Grades/GradesTaskEditForm.aspx</Display>
</FormUrls>
</XmlDocument>
</XmlDocuments>


After I installed the updated content type and tried to edit a task, WSS kept showing me the default EditForm.aspx page, not the GradesTaskEditForm.aspx. Then I tried to deactivate and uninstall the content type for many times, but WSS still used the default page.

Finally, I saw a line in the "Real World SharePoint 2007" book: When you use Feature to install a new version of Content Type, WSS does not support cascading update if inherited content type is used somewhere. (No quote)

Oh ... That is the reason why I failed to overwrite the old content type definition -- WSS kept GradingTask's meta data for the list even after the Feature was uninstalled.

So I deleted all items of that GradingTask type, removed workflow setting, detached the content type from the list, deactivated/uninstalled the feature, deleted the list and then reinstalled/activated the feature, ... ... finally my lovely custom Edit page showed up :)

According to the book, to support cascading update I need write code using WSS object model API to force cascading update ... I would try that later.

[Updated 12/28/2007] I saw this great article this morning to deal with the mess of Content Type inheritance.

Can I use SharePoint Workflow on SPGridView?

Nowadays, it is quite easy to find articles about how beautiful it is to use Microsoft SharePoint 2007 Workflow and InfoPath to manage Documents or List.

But I am too poor to buy MOSS 2007 and InfoPath, is it possible to use WSS 3.0 Workflow frame to manage normal business objects (e.g. purchase orders, law suit cases) in an ASP.NET SPGridView on a WSS 3.0 site? Or to say, can I build a WSS Workflow and related ASP.NET pages (Workflow Association, Instatiation, Modification, and Task Edit pages) in Visual Studio, then use that workflow for each item of an ASP.NET SPGridView and modify data stored in a standalone database (not WSS Content database)?

From my current understanding, the answer is: No, because SharePoint Workflow processes SPListItem, not item of SPGridView; and of course, you are not supposed to create task from your code because the task is of SPWorkflowTask type that can only be created from SPWorkflow.

Ok ... fine. How about creating a SharePoint List to hold my business objects but I need save my business objects in a separate database?

Well ... To use SharePoint List, you have to create list columns inside SharePoint Content database, not in other databases.

&*%*^%%^$

So from my current understanding, if I want to use WSS 3.0 workflow framework for my own business objects in a standalone database (S_DB), I have to create a List and several columns (for display and search purposes) in WSS site. Those columns are duplicated because they are already defined in database S_DB.

When user starts workflow on the list item, the workflow (Instatiation) ASP.NET page will use ADO.NET code to load other fields from database S_DB. Then the ASP.NET page should save updated data back to S_DB, and at the same time save the data of the List columns to WSS Content database too.

Is there a better way to avoid data duplication in WSS Content database and the other standalone database?

Convert Access database to SQL Server 2005

In one of my projects, I need analyze data in an Access application. Frankly speaking, that is the best Access application I have seen so far: with many front-end Access forms, users can input data to the back-end single Access database.

But Access is not designed for client-server mode anyway. A lock file is needed to only allow one user to lock a table at one time. Sometimes, users have to wait for minutes for others to finish a simple data update operation.

For me, I am not a fan of Access, although I was amazed by how that Access application worked. So I decide to convert to SQL Server database.

But how? Although SQL Server Integration Service (SSIS) can import data from Access, it is hard to maintain database settings (e.g. foreign-key relationship, etc). Today, I found SQL Server Migration Assistant for Access from Microsoft. Now my life is easier :)

Why "using" is bad for your WCF service host

I scratched my head this morning for a WCF service host program. It threw a very generic exception like this:

“The communication object, System.ServiceModel.ServiceHost, cannot be used for communication because it is in the Faulted state.”

The exception above had no any useful information about where the real problem was. The logic of my program was simple:

using(ServiceHost host = new ServiceHost(
typeof(MyService), new Uri("http://localhost:8080/MyService"))
{
host.Open();
... ...
}

When I looked inside Output of VS 2005, I saw this log information:

'System.ServiceModel.AddressAlreadyInUseException'

But why WCF did not give me that exception directly? Finally, this blog explains the reason: Why "using" is bad for your WCF service host.
------------------------------------------
ServiceHost Host = null;

try
{
Host = new ServiceHost(MySingletonService);
Host.Open();
Console.ReadKey();
Host.Close();
}
finally
{
if (Host != null)
((IDisposable)Host).Dispose();
}

The configuration exception is thrown by the “Host.Open()” line, the code jumps into the finally block and tries to dispose the host. Here the host is not null but it is in a faulty state, this means that it cannot be disposed and this raises the second exception that you usually see on your application.

The lesson learn is “do not use ‘using’ to host your WCF service”.

------------------------------------------

Traditional Chinese medicine to cure "incurable" diseases

I did not read technical books for weeks after I finished my project (which is rare for me), because I was reading/studying a more important thing for our daily life: traditional Chinese medicine, that can even cure some so-called "incurable" diseases, such as cancers, or AIDS!

Frankly speaking, I had been disappointed by Chinese doctors for a long long time since I was a child. My previous impression was Chinese medicine/method were too slow for illness, until recently I began to know several real Chinese doctors and their treatments.

One doctor is Mr. Ni Haisha (Please don't be cheated by his English site for Acupuncture, that is only because USA has no license for Chinese medicine yet). His Chinese site has far more great information about why/how about cancers than his English site.

Chinese medicine takes our body as a whole system. For example, the root reason for the breast cancer is because heart and small intestine are weak. But Western medicine takes our body as separate items. That is the reason why Western medicine does not work.

If Chinese medicine is so good, but why the medicine from many Chinese doctors is not effective, and even many Chinese doctors take western medicine by themselves for illness? The reasons are quite complex. Basically, Chinese medicine is like "art", not many good doctors exist; many Chinese doctors learned in a wrong way; Chinese government admired western technology too much and ignored real jewels/wisdom in the long Chinese history ...

How to find a good doctor? If your feet get warm after you take Chinese medicine, then that doctor is a good doctor; otherwise, if you still feel cold in your feet, and your symptoms still exist, then that doctor is likely a fake Chinese doctor.

Currently, I know two Chinese doctors are good: Mr. Ni and Mr. Huo

# in URL

It may be obvious to many people: if # is included in URL, it refers to a relative location of current HTML page in browser. For example, URL "http://somewhere.com/home.htm#section1" refers to ID "section1" on "home.htm" page. So what's the point to mention again here?

The interesting thing happens when the URL is used between ASP.NET web services: The IIS server side cannot get the whole URL if a client sends URL with #. Basically, the ASP.NET web service can only get the front part of URL. Everything behind # will not be available to web service.

So if web service client wants to send parameter ("#1", "#2", or "#3") to web service, sorry, the service side cannot see that parameter.

A bug in my recent project was related with this issue: a telephony system sent dynamic URL to web services, sometimes with # in the URL.

Crystal Report generates PDF in different fonts on different servers

We were satisfied with Crystal Report (CR) to generate PDF on the fly until we put CR templates on production servers.

The CR templates were tested on DEV and QA servers without any problem. But when the templates were put onto production box, we were amazed how messy the generated PDF looked like: the font size were mysteriously changed and paragraphs overlapped! @^@

I searched for reasons on Internet for hours, until I found one possible answer here: Typically when you are seeing page formatting issues on different machines, it could be because of printer drivers (or lack of). The reporting engine relies on the printer driver configured on the machine to provide information so that a page can be properly rendered. If you designed the report on your dev machine which is using PrinterA and then deploy to another machine using PrinterB, the formatting could be off.

My program was a .NET web service to create PDF document using ExportToDisk not PrintToPrinter:
oDocument.ExportToDisk(
ExportFormatType.PortableDocFormat, sOutputFile);

so I wondered if the printer was the real problem. After I was told the production server pointed to the exact same printer as QA server, I reluctantly asked IT to check version of printer driver on both servers.

Then ... IT told me that the servers had different versions of printer driver even they pointed to same printer. After IT installed the same latest drivers on servers, the formating issue was resolved. :)

Although we had to postpone production delivery, it's good to know some software use printer driver to arrange layout internally.

Zero to Biztalk Weekend

In the wonderful "Zero to Biztalk Weekend", Biztalk expert Geoff Snowman gave us two-day FREE hands-on labs and demos about Biztalk 2006 (and R2)! The hands-on labs were well designed and the lab document was in great details.

Biztalk is a useful product to integrate systems together. From concept, it receives messages from Receive Adapter/Port, processes messages in Orchestration (optional), and sends out messages using Send Adapter/Port. Biztalk can run long-running transactions, which is very important for real world business.



Below are the agenda and my comments for the labs:


Saturday (06/02/2007)

1. Architecture and Content-Based Routing: Deciding Where to Send a Message

This hello-world type XCopy lab uses File adapter to receive and send files without transformation. This is a good introduction of Biztalk adapter concept.

2. The BizTalk Mapper: Transforming Between Message Formats

Biztalk uses XML intenally to represent messages. When Biztalk integrates multiple systems, it is necessary to transform different data schemas into one internal schema; after business process, Biztalk will transform internal XML to according external schema.

But how to deal with non-XML input, such as flat file? Well, that is a topic in the second-day lab.

3. The SQL and FTP Adapters: Sending Messages to Databases and IIS

FTP adapter has the same logic with normal FTP client software, which is easy to use.

SQL adapter is a little complex: to map Biztalk XML schema to database table or stored procedure parameters. Fortunately there is a wizard to generate the interesting SQL schema.

4. Creating a Simple Business Process. Publishing a Business Process as a Web Service. Using the SOAP Adapter

Orchestration with complex workflow can be published as a normal web service. Unlike using File adapter where Biztalk checks file system periodically for new file, Web Service request can go directly into Message Box without waiting for Biztalk polling. I believe Biztalk server uses similar machenism of SQL Server Notification Service to notify an Orchestration a request is coming.

5. Correlation: Which Instance of My Business Process Sees My Incoming Message?

Correlation has been one of exciting build-in features of Biztalk for a long time. Correlation is normally used to match responses with proper original requests sent out by Orchestration. You do not need write code for correlation.

Sunday (06/03/2007)

1. The Flat File Wizard and the Pipeline Designer: Dealing with Text Files.

Biztalk 2006 has a new Wizard to convert Flat file into XML. The wizard parse a sample flat file data to let user select delimiter and generate XML schema. The wizard is easy to use.

But how about binary file? Is there a wizard to parse and generate XML schema? No, you have to write your own pipeline component to parse binary format.

2. Integrating with SharePoint and InfoPath

Biztalk has Human Workflow solution. Its name sounds good, but remember: Do not use it! The reason is we have SharePoint 2007 with built-in workflow feature. SharePoint and InfoPath are good tools for people to approve/decline messages, and Biztalk can communicate with SharePoint database.



3. The Business Rules Engine: Separating the Business Logic from the Application

Biztalk is not only used for we developers, of course. Business people has a tool to modify business rules (e.g. change pricing rate, change approve/decline rules).

4. Business Activity Monitoring: Tracking the Business Process (Demo)

BAM is valuable to business people to track activities in their own vocabulary. I am not so sure if it is built on SQL Server Reporting Service or not, but it looks similar.


Overall, the two-day training is very good to know architecture of Biztalk and have some hand-on experience. With time limit, it is hard to know the internal of Biztalk in only two days. I am waiting for level 200 or 300 training in the future.

To remove “Is Identity” setting in SQL Server: Not simple

Yesterday I found a seems-like-simple SQL problem: It is a simple task inside SQL Server Enterprise Manager (Management Studio), but there is no simple single SQL statement to set “Is Identity” to “no” for a table column. Because the setting is not a constraint, “alter table” statement does not work.

It turns out I have to create a same temporary column, copy all data to that new column, remove the original column, and rename the temporary column back to that original name. Another way is to create a temporary table without setting "Is Identity" and copy all data ... Oh my, such a “simple” work!

But fortunately there is a tip available to generate SQL script for database schema change: In SQL Server Enterprise Manager, when you change table schema, you can let Enterprise Manager generate the schema change script for you. The most left button of this tool bar is used to “Generate change script”:


Yesterday, I used it to generate a complex script to remove “Identity” setting for a column:
-- To remove Identity setting of the Id column
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.partner_attribute_name
DROP CONSTRAINT DF_partner_attribute_name_last_update_date
GO
ALTER TABLE dbo.partner_attribute_name
DROP CONSTRAINT DF_partner_attribute_name_creation_date
GO
-- Create a temp table
CREATE TABLE dbo.Tmp_partner_attribute_name
(
partner_attribute_name_id int NOT NULL,
attribute_name varchar(50) NOT NULL,
description varchar(200) NOT NULL,
last_update_date datetime NOT NULL,
creation_date datetime NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.Tmp_partner_attribute_name ADD CONSTRAINT
DF_partner_attribute_name_last_update_date
DEFAULT (getdate()) FOR last_update_date
GO
ALTER TABLE dbo.Tmp_partner_attribute_name ADD CONSTRAINT
DF_partner_attribute_name_creation_date
DEFAULT (getdate()) FOR creation_date
GO
-- Copy all data to the temp table
IF EXISTS(SELECT * FROM dbo.partner_attribute_name)
EXEC('INSERT INTO dbo.Tmp_partner_attribute_name
(partner_attribute_name_id, attribute_name
, description, last_update_date, creation_date)
SELECT partner_attribute_name_id
, attribute_name, description
, last_update_date, creation_date
FROM dbo.partner_attribute_name
WITH (HOLDLOCK TABLOCKX)')
GO
DROP TABLE dbo.partner_attribute_name
GO
EXECUTE sp_rename N'dbo.Tmp_partner_attribute_name'
, N'partner_attribute_name', 'OBJECT'
GO
ALTER TABLE dbo.partner_attribute_name ADD CONSTRAINT
PK_partner_attribute_name PRIMARY KEY CLUSTERED
(
partner_attribute_name_id
) ON [PRIMARY]
GO
COMMIT

Note: You should generate the script BEFORE you save the changes in EM. Otherwise, that button will be disabled.

A small compiler - Wilco Syntax Highlighting

Although I am quite busy these days for my projects at hand, I still try to find time to do what I really want: to dig into compiler, operating system, and CLR framework.

Yesterday, I spent hours to analyze a popular syntax highlighter tool - Wilco SyntaxHighter, because it is a small compiler to some degree. :)

The highlighter parses string source (the code to be highlighted) to scan tokens (comment, string, key word). Each token includes position/length information in the string source and related with highlighter style data. Then the parser reads the source again to merge those parsed tokens. The string segment of the token will be updated with style data. Other string segment will leave as-is.

The good feature of that parser is to build a scanner chain. For example, to parse C# code, these scanner will be used: CommentBlockScanner (/* ... */) -- CommentLineScanner (//) -- StringBlockScanner (@) -- StringLineScanner ("") -- WordScanner. When the current and following characters match CommentBlockScanner, the CommentBlockScanner will continue to read characters to the end of the comment block and take that block as a Comment token; if the current character does not match CommentBlockScanner, then it may match the next scanner in the scanner chain ... If the character does not match any scanner, then it does not belong to a token and should be ignored.

For different type of language (e.g. Java, CSS, etc), we can build and use different scanner chain. But the basic parsing logic is still same.

The concept of Compiler is very useful when generating code dynamically. When the theory of "Software Factory" becomes real, code generation tool will be the fundamental in the system.