XAF - 10 - Advanced data layer features

XAF Team Blog
31 May 2008

This is post no. 10 in the mini series "10 exciting things to know about XAF". You can find the announcement of the series here.

I've reached the last post in the mini series, and this is going to be about the functionality XAF inherits from the underlying infrastructure that our ORM product XPO provides. For a start, this is where XAF gets its compatibility with a vast number of different database systems from.

There are two different ways of changing the database type XAF connects to. The very easy approach, which we've implemented for a few of the most common backends, is to use the connection components in the Application Designer within Visual Studio. For backends that aren't directly supported by a connection type in the Designer, you must configure the connection string in the app.config and/or web.config file(s) manually.

Of course it is important to know what connection strings you need to use. Generally I guess if you're using a particular RDBMS, you are probably more familiar with the connection string format it uses than I am, so in reality it's probably not a big problem. Your RDBMS docs should give you details, as well as online sources like http://www.connectionstrings.com/. For the purpose of using the connection strings with XPO/XAF, there's one other thing that's important though: the connection string format must be recognizable by our libraries, so they know what database type to connect to. There's a pretty useful heuristics at work to figure this out, but sometimes connection strings look so similar that the distinction isn't easy.

For that reason, we have introduced a flag called "XpoProvider" into the connection string, which tells XPO explicitly which connection provider it has to use. The other extremely helpful thing is that all XPO connection providers have a helper method GetConnectionString, which takes a few typical parameters and generates a correct connection string, including the XpoProvider flag, for you. To take advantage of this, create a new Console Application project and add references to DevExpress.Data, DevExpress.Xpo and, if your provider is one of the less common ones, DevExpress.Xpo.<version>.Providers. The namespace DevExpress.Xpo.DB now has all the various Connection Provider classes, and you can output valid connection strings on the console like so:

Console.WriteLine(MSSqlConnectionProvider.GetConnectionString(".", "mydb"));
Console.WriteLine(MySqlConnectionProvider.GetConnectionString("localhost", "user", "password", "database"));
Console.WriteLine(PervasiveSqlConnectionProvider.GetConnectionString("localhost", "user", "password", "database"));

This example will render the following output:

XpoProvider=MSSqlServer;data source=.;integrated security=SSPI;initial catalog=mydb
XpoProvider=MySql;server=localhost;user id=user; password=password; database=database;persist security info=true;
XpoProvider=Pervasive;Server=localhost;UID=user;PWD=password;Data Source=database;

In addition to this, XPO also supports connecting to a service of some description, over a remote connection. Over time I've written a whole lot of blog posts on this topic, which I recommend you read if you're interested in this scenario. Here's the main XPO blog, which you should probably read through yourself. Here's an incomplete list of the interesting posts on the subject:

The connection strings that make XPO connect to XML Web Services and .NET Remoting are also supported by XAF directly.

Finally, if you want to influence the way the XPO connection is set up and do things you can't specify through the connection string, it is possible to hook into the process of setting up the XPO connection provider and data layer. To do this, you override the method OnCreateCustomObjectSpaceProvider in your WinApplication and/or WebApplication class(es) and return your own version of an ObjectSpaceProvider. It isn't hard to derive your own ObjectSpaceProvider from one of the standard ones and handle data layer creation in any way you see fit -- if there's interest in this and reading the source of ObjectSpaceProvider.cs doesn't help you, leave a comment and I'll try to create a sample when I have time.

Some other interesting features of XPO that you could enable or configure using this approach are the data layer caching and SqlDependency features. Of course you can switch on SqlDependency support by using the right XpoProvider flag, as described in the article, and this also enables data layer caching. But SqlDependency is a special feature for SQL Server support, and setting up data layer caching for other backends currently requires the OnCreateCustomObjectSpaceProvider approach outlined above.

So, that's all I have to say today. I hope the series was interesting -- I'll hand the post on styling ASP.NET applications in as soon as it makes sense, again my apologies for that one. I'm almost on my way to TechEd now -- if you're there, say hi!

Free DevExpress Products – Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We’ll be happy to follow-up.
Greg Munn
Greg Munn

"The connection strings that make XPO connect to XML Web Services and .NET Remoting are also supported by XAF directly"

Does this include WCF as well?  I've tried to implement WCF with XAF (8.1.x) and have not had a lot of success - I'd like to see an updated example that did this if that were possible.  The changes to XAF since the WCF sample was created leave me a little confused as to where and how to achieve this correctly.



1 June 2008
Binish Peter
Binish Peter

I would like to see the example

reason: I have custom MSSqlConnectionProvider to use date manipulation features of SQL Server

2 June 2008

thank you Oliver.. it has been fun reading these posts.. hopefully there will be even more along similar tracks.. cheers!

3 June 2008
Sebastia Prat i Pons
Sebastia Prat i Pons

Thanks Oliver, I'm using the publication service and works fine! It's a good approach for distributed aplications.

It will be really interesting to have new project in the solution (6) that deals with the remote data and help us to put the most critical remote BLogic processes to make the product more robust, like generating 800 invoices at once.

2 July 2008
Dan Arnold
Dan Arnold

"The connection strings that make XPO connect to XML Web Services and .NET Remoting are also supported by XAF directly."

For the life of me, this statement makes no sense.

XPO doesn't even support a connection string for a service based datastore.

Are you referring to the normal database connectionstring that is used in the Publication Serverice XML file?

If so, that, how is that a directly supported connection string that XAF understands?

I wish your component sources and XPCollection components wuld actuallytake a connectionstring the referred to a url, port and service name, and if it does, I'll be thrilled.

Please show me a connection string, as you decribe here, and where it is used in XAF directly.




Trying to learn to use your products is always hard due to the multitude of sources (fragmented help and documentation). I have and will continue to push DevExpress to not only provide hyperlinked help, which is impossible to print for offline use, bu to also provide DOCUMENTATION (NOT HELP FILES).

Otherwis we are faced with reading confusing blog entries that refer to olderblog entries or KB aticles that aren't always valid anymore.

Please excuse my off topic rant here...but also please hear what your customers are asking for.

27 July 2008
Oliver Sturm (DevExpress)
Oliver Sturm (DevExpress)


As I say above, XPO supports all sorts of connection strings, and details are given on the pages linked from this article. In particular, an example for connections to web services is given on this page, also linked from the article above as the followup on the post "Using Web Services with XPO".

The post shows this example for a connection string that goes to a web service (and yes, it does contain URL, port and service name):


In XAF, you can use a connection string of this format (or any other format support by XPO) either in the XafApplication.ConnectionString property (that's the one that can be configured through the application designer in VS) and/or in the app.config/web.config files.

28 July 2008
Dan Arnold
Dan Arnold

Sorry I wasn't more specific. I have been using your XPOPublication service with an HTTP channel and binaryformatter (.net remoting)

I have been unable to get this to work by overriding OnCreateCustomObjectSpaceProvider.

Do you see anything wrong with the code ?

The service works fine with the Non-XAF application.

       protected override void OnCreateCustomObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args)


           string url = @"dev/WindfallDataService.rem";

           IDataStore dataStore = WindfallObjectSpaceProvider.CreateInstance(url);

           args.ObjectSpaceProvider = new ObjectSpaceProviderSimple(new SimpleDataLayer(dataStore));


   internal static class WindfallObjectSpaceProvider


       internal static IDataStore CreateInstance(string url)



           IDataStore dataStore = (IDataStore)Activator.GetObject(typeof(IDataStore), url);

           return dataStore;


       private static void RegisterChannel()


           BinaryClientFormatterSinkProvider clientSink = new BinaryClientFormatterSinkProvider();

           HttpChannel channel = new HttpChannel(null, clientSink, null);

           ChannelServices.RegisterChannel(channel, false);



28 July 2008
Sigurd Decroos
Sigurd Decroos

A very good sample (VB.Net if possible) would be very nice. All those words and links are nice for people with a lot of time to read. Persons like me need a clear example that speaks for itself and when we don't understand something, there's always the help or forum :)

3 August 2008
10 exciting things to know about XAF - eXpress App Framework Team

Pingback from  10 exciting things to know about XAF - eXpress App Framework Team

22 August 2008
Using XAF with Embedded Firebird « Development Technobabble

Pingback from  Using XAF with Embedded Firebird « Development Technobabble

27 February 2010
Marco Kummer
Marco Kummer

Hi Oliver

I currently have a customer where I need to use some form of XPO remoting. Right now I'm using the web service approach beacause it seemed the easiest to set up. However, my customer is having severe performance problems, even though the business objects aren't very complex.

Can you tell me which of the remoting methods would be the fastest (Web service, .NET remoting, WCF, RemObjects..) ? Or do you see any good way to speed up the web service approach?

Thanks a lot in advance!


23 February 2011
Uriah (DevExpress Support)
Uriah (DevExpress Support)

I am afraid I do not have enough experience to share it with others. But probably, the following links will be useful for you:



23 February 2011

Please login or register to post comments.