Wednesday, January 25, 2006

In C#, I take an entity and serialize it to XML and pass it to a stored procedure which takes the data and inserts it into a table. I have several datetime properties within my entity and when I serialize it to xml, the datetime looks like this:
2005-11-14T13:37:38.1516436-06:00.
Here is the C# code that serializes the entity:
XmlSerializer xmls = new XmlSerializer(typeof(SaleItem));
using (MemoryStream ms = new System.IO.MemoryStream())
{
xmls.Serialize(ms, si);
ms.Seek(0, SeekOrigin.Begin);
StreamReader tr = new StreamReader(ms);

return tr.ReadToEnd();
}
Anyway, sp_xml_preparedocument does not like the datetime value generated by the XmlSerializer. The only way I know of to get around this problem is to:
1) Hand walk the entity and create my own XML (don’t use XmlSerializer)
2) Parse the string and get rid of the milliseconds (after 3 characters) and the -06:00.
Either way seems kind of like a pain and does not flow very well. Does anybody have a better way to do this?

The problem are indeed the beyond millisecond resolution and the timezone indicator. Can you generate your value with milliseconds only and the timezone Z or no timezone instead? Use casting rules for that in SQL Server 2005. In SQL Server 2005, you can write:

declare @x xml
set @x = N'2005-11-14T13:37:38.1516436-06:00'
select @x.value('xs:dateTime(/EndDateTime[1])', 'datetime')


Note that this however performs two casts, so if you can change the value generation, that would be better.
Alternatively, if you can provide a schema that types the element as xs:dateTime, you will not have to explicitly cast it to xs:dateTime.

Monday, January 23, 2006

Is there another way I can create the SSL certificates for ADFS than using the SelfSSL tool?
If you are building proof-of-concept software and not ship bits, you can use makecert.exe to generate one for you.
Here is an MSDN link with the necessary information:
http://msdn2.microsoft.com/en-us/library/ms186362.aspx

Sunday, January 22, 2006

Calculate the Last Logon Time in Windows 2003

There is a nice article in technet website about calculating the Last Logon Time in Windows 2003 Active Directory.
Here the script:

Set objUser = GetObject("LDAP://cn=Ken Myer, ou=Finance, dc=fabrikam, dc=com")
Set objLastLogon = objUser.Get("lastLogonTimestamp")
intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart

intLastLogonTime = intLastLogonTime / (60 * 10000000)
intLastLogonTime = intLastLogonTime / 1440
Wscript.Echo "Last logon time: " & intLastLogonTime + #1/1/1601#


We must know few catches around it:
- lastLogonTimestamp attribute in Win 2003 keeps track of the last time a user logged on to the domain, and also replicated from one domain controller to another.
- lastLogonTimestamp is replicated only once every 14 days. This helps limit replication traffic, although it also means that the lastLogonTimestamp for any given user could be off by as much as 14 days.

More information at http://www.microsoft.com/technet/scriptcenter/topics/win2003/lastlogon.mspx

Wednesday, January 11, 2006

Service Pack 1 (SP1) for ADAM

Service Pack 1 (SP1) for Active Directory Application Mode (ADAM) for the English language is now available.
http://www.microsoft.com/windowsserver2003/adam/default.mspx

ADAM SP1 new features are:
- Active Directory to ADAM Synchronizer tool.
- ADAM users can bind to an ADAM instance by using Digest authentication.
- Active Directory Schema Analyzer tool.

- Newer version of LDP tool with ACL editor.
- Password chaining to AD users through ADAM proxy objects
- Users can be created in the configuration partition so that ADAM users can be ADAM administrators.

Tuesday, January 03, 2006

How to express time in ISO 8601 format?
DateTime myTimestamp = DateTime.Now;
string t = String.Format("{0:u}",myTimestamp);
t = t.Remove(19,1);
string s = String.Format("{0}.{1:fff}Z",t,myTimestamp);
Is there a way to get DataTable from DataView? I am creating a DataView from a DataTable and applying some filters and sorting to Dataview. But I want to have DataTable out of this new Dataview (filterd/sorted).
In .NetFramework v1.0/v1.1 you can do:
Dim dt2 As DataTable = dv.Table.Clone() ‘ copies the structure
For I = 0 To dv.Count – 1
dt2.ImportRow(dv.Item(I).Row) ‘ copies a row
Next I
My ASP.NET form is many screens long. After user presses the button and the form is posted back to itself, I'd like to scroll it to the location where the button was pressed. What is the easiest way to achieve that?
You could use javascript, something like .scrollIntoView() for this.
string startupScript = @"";
Page.RegisterStartupScript("ReturnToAnchorAfterPostback", startupScript);

When ADSI binding fails, can the program know that is the userid that is not valid rather than the password is not match? Will doing a lookup to the lists of user take too much time?
It depends on how many objects are in your forest/domain. Searches are efficient if you use indexed attributes.

When changing password using ADSI, will the program know that the password actually not meeting the complexity requirement?
you'll get 800708c5 error.

Try C:\>net helpmsg 2245

Native XML Web Services for SQL Server 2005

Get an overview of how to set up and use XML Web Services using SOAP/HTTP inside SQL Server 2005 (formerly known as "Yukon"). Illustrative examples are included. To get the most from this paper, you should have a basic understanding of Web service technologies including HTTP, SOAP, and WSDL.

http://msdn.microsoft.com/data/default.aspx?pull=/library/en-us/dnsql90/html/sql2005websvc.asp

URL Rewriting in ASP.NET

Examines how to perform dynamic URL rewriting with Microsoft ASP.NET. URL rewriting is the process of intercepting an incoming Web request and automatically redirecting it to a different URL. Discusses the various techniques for implementing URL rewriting, and examines real-world scenarios of URL rewriting.

http://msdn.microsoft.com/asp.net/using/building/web/default.aspx?pull=/library/en-us/dnaspp/html/URLRewriting.asp