in
Forums
Blogs
Files
Devexpress.Com
ClientCenter
Support Center
DevExpress Channel

Gary's Blog

XPO Cookbook #2 – Change the Default Database

Problem

You want to persist your objects to a MS SQL Server database instead of the default access database

Solution

using System;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;

class Program {
    static void Main(string[] args) {
        string conn =
            MSSqlConnectionProvider.GetConnectionString(".",
                "XPOCookbook");

        XpoDefault.DataLayer =
            XpoDefault.GetDataLayer(conn,
                AutoCreateOption.DatabaseAndSchema);
    }
}

Discussion

To connect to a SQL Server database, instead of the default Access database, the first thing that we have to do is to create the required connection string by calling the GetConnectionString() method on the MSSqlConnectionProvider class and passing in the server name and database name. Having thus obtained the connection string, we can then make our database the default one used by XPO by setting the XpoDefault DataLayer property to the result of calling the GetDataLayer() method, on the XpoDefault class, passing in the connection string and setting the AutoCreateOption.

Technorati tags:
Digg This
Published Aug 25 2008, 04:22 PM by Gary Short (Developer Express)
Filed under: ,
Technorati tags: XPO, XPO Cookbook

Comments

 

Luca Poretti said:

This is nothing more than the first 3 items of your KB A2944.

I suggest to put a link somewhere to A2944 (and others already present, well written, regulary updated, KB articles) to increase visibility of these basic informations instead of repeating the same things in another place.

I don't want to blame, use this as a positive suggestion...

Hope to see some more focused info in the next recipe.

Always thanks for your work.

August 25, 2008 11:59 AM
 

Gary Short (Developer Express) said:

Hi Luca, thanks for your feedback. You are correct this information is available elsewhere, however, if you read the comments in the post (community.devexpress.com/.../the-expressapp-application-framework-project-mojave-and-show-stoppers.aspx) you will see that some customers have trouble in finding some information and so part of the reason for doing this cookbook is to surface this information and provide another mechanism for customers to find it.

Another reason for providing this information is that you have to start somewhere and the begining seems a logical place. If I started where you wanted me to start I dare say I'd get comments asking why I didn't start at the begining. Not all the recipes are going to be of interest to all customers

August 25, 2008 12:13 PM
 

Richard Sykora said:

Hi Gary,

it would be nice if there would be a cookbook for 2 different connections to 2 different databases (for example on the same SQL Server), and how you have to work with sessions.

Btw its a very good idea show the mnemonics of the templates if you use coderush

Thanks for your work

August 25, 2008 5:44 PM
 

Malisa Ncube said:

Gary

it would be nice for you to include details of using XPO in ASP.NET with membership management, state management and session management in your cookbooks.

Are you hoping to have a Membership provider for ASP.NET? It would be nice to see, how we can quickly make one - which is really effective as the one introduced in ASP.NET 2.0.

I would suggest that you provide (vsi) templates.

Thanks

August 26, 2008 2:20 AM
 

Steve Sharkey said:

Going well so far Gary, I agree with comments regarding finding information being a bigger issue than the information not being there. Any intention of "binding" the cookbook into a suplimental help file for downloading? It's nice having information at your finger tips but sometimes (when on the move) there are those of us with no internet connection.

Not wanting to start an "old argument" here but why are examples so often in C# not VB? I keep hearing that VB programmers are "inferior" to C# ones - so why is it we appear to be deemed better at converting C# to VB than C# programmers are at converting the other way around?

August 26, 2008 3:32 AM
 

Gary Short (Developer Express) said:

@Richard, @Malisa, more advanced repices will be coming later.

@Steve, hmm, there is no plans to bind this into a help file at the moment, mainly because I hadn't thought of it. :-) Would anyone else be interested in such a thing if it were possible?

August 26, 2008 5:50 AM
 

Richard Sykora said:

Hi Gary,

that would rock as an extra section in the help file ;)

August 26, 2008 9:21 AM

Leave a Comment

(required)  
(optional)
(required)  
Verification code: Required
   
Add
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED