Team System caches RegistrationEntries client side.

For about two months I have been working on an adapter that reads data from a source database and uploads it to custom dimensions in the TfsWarehouse. Yesterday I ran into a strange (at least, at that moment) problem. First I’ll explain the situation.

In the adapter I have a piece of code that queries the RegistrationEntries from the TfsIntegration database using the IRegistration service. The RegistrationEntry contains the database name of my source database and the database server name. I added the RegistrationEntry using the tfsreg.exe tool, providing an xml file with the data to store. An example of such an xml file is provided below. 


xml version=1.0 encoding=utf-8 ?>

<
RegistrationEntries>
&nbsp; <
RegistrationEntry>
&nbsp;&nbsp;&nbsp; <
Type>MyEntryType<Type>
&nbsp;&nbsp;&nbsp; <
ChangeType>Add<ChangeType>
&nbsp;&nbsp;&nbsp; <
Databases>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <
Database>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <
Name>MyDB<Name>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <
DatabaseName>MyDbName<DatabaseName>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <
SQLServerName>MyDBServer<SQLServerName>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <
ConnectionString>Server=@SQLServerName@;Database=@DatabaseName@;Integrated Security=SSPI<ConnectionString>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <Database>
&nbsp;&nbsp;&nbsp; <Databases>
&nbsp; <RegistrationEntry>
>


If you want&nbsp;access this information from code you do can something like this:


TeamFoundationServer server = TeamFoundationServerFactory.GetServer(“http://mytfs:8080“);

RegistrationEntry[] entries = ((IRegistration)server.GetService(typeof(IRegistration))).GetRegistrationEntries(“MyEntryType”);
RegistrationEntry entry = entries[0];

Console.Write(RegistrationUtilities.GetConnectionString(entry, “MyDB”));


The RegistrationUtilities class replaces the @SQLSevername@ and @DatabaseName@ by the corresponding elements of the RegistrationEntry and creates the ConnectionString for you.
If you just need to access the database name or the server name you can do that like this:


string databaseName = entry.Databases[0].DatabaseName;&nbsp;&nbsp; //using index 0 assuming that there’s just one database
string serverName = entry.Databases[0].SQLServerName;&nbsp;&nbsp;&nbsp; //to keep the example simple
string name = entry.Databases[0].Name;


Well, this&nbsp;should help you getting it to work if you&nbsp;would want to.&nbsp;Let’s get on to&nbsp;my problem now.
I used the tfsreg.exe tool again to update the setting&nbsp;to point to another database. Unfortunately the setting didn’t change when I tried to access it from code.&nbsp;Thinking the setting is cached by tfs I thought that an iisreset would do the thing….Not! Then I started&nbsp;thinking and searching for a&nbsp;location and&nbsp;file where tfs could store this information&nbsp;client side. It turned out that different kinds of settings and information&nbsp;is stored (per user) in different files in this folder:
C:Documents and Settings<user name>Local SettingsApplication DataMicrosoftTeam Foundation1.0Cache


On my machine it contains&nbsp;two files: ServerMap.xml, VersionControl.config and folder&nbsp;with a name like _http. The ServerMap.xml contains key/value entries&nbsp;for a service (e.g. http://mytfs:8080/Services/v1.0/Registration.asmx) and the instance id.
The VersionControl.config contains some info about workspaces etc.


Most important in my case was the file RegProxyFileCache.xml in the _http folder. It contains all the RegistrationEntries from the TfsIntegration database. So that’s the place where it gets the information from. I didn’t figure out what the cache-time out is. If you run into this problem also, delete the file and you’ll get the updated RegistrationEntry.


Hope this helps!