I have built a process to extract data from active directory via a C# script component in SSIS. This data needs to be loaded into SQL Server. I am running into problems where the DistinguishedName (DN) and CanonicalName (CN) contain the double quote (") and backslash (\) escape characters (see weblink below).
From what I can tell, all escape characters should have a leading backslash (\). Is this correct? I am asking because it appears that I have found instances where this is not true and so I am unable to remove these escape characters, which is causing SSIS import to fail with the error that it cannot find the column delimiter for DN and CN respectively. Note: I have set the double quote (") as a column delimiter in the SSIS connection manager. Is there a way to handle this in code or do I need to have the AD admin fix it?
string strDistinguishedName = objConverter.ConvertToString(searchResult, "distinguishedName").Replace("\"","").Replace("\\"","");
Input1: "CN=SomethingHere “Got Rocks\\\" OtherTextHere,OU=Blah,OU=Bleh,DC=jweezy,DC=com"
Output1: "CN=SomethingHere “Got Rocks OtherTextHere,OU=Blah,OU=Bleh,DC=jweezy,DC=com"
Input2: "CN=SomethingHere2 “Got Gravel" OtherTextHere2,OU=Blah2,OU=Bleh,DC=jweezy,DC=com"
Output2: "CN=SomethingHere2 “Got Gravel" OtherTextHere2,OU=Blah2,OU=Bleh,DC=jweezy,DC=com"
The problem seems to be caused by the lack of escape character, so I believe the inputs should be as follows:
Input1: "CN=SomethingHere \“Got Rocks\" OtherTextHere,OU=Blah,OU=Bleh,DC=jweezy,DC=com"
Input2: "CN=SomethingHere2 \“Got Gravel\" OtherTextHere2,OU=Blah2,OU=Bleh,DC=jweezy,DC=com"