Print Page | Close Window

DataSourceKeyResolver

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2970
Printed Date: 04-Sep-2025 at 11:31pm


Topic: DataSourceKeyResolver
Posted By: rickadams
Subject: DataSourceKeyResolver
Date Posted: 21-Sep-2011 at 1:42pm
I wish to implement a DataSourceKeyResolver on my DevForce BOS. I have created the class which implements IDataSourceKeyResolver. wish This class  will lookup the Database connection string in the Database and return the connection string based on the keyName and keyExtension. I wish to use a DevForce Entitymanager to return the required connection string. My application does not allow anonymous access so i must use an authenticated EM to perform the query. I don't seem to able to create the EM on the server side that is logged in. I must be missing something obvious here so would you mind showing me the code required to perform this. Here is my current code that is not working
   private static String GetConnectionString(string keyName, string keyExtension) 
    {
        try
        {
            Log.Information("LEAF_DataKeyResolver""GetConnectionString", keyName + "  +  " + keyExtension);
            ConfigInfoEntities context = new ConfigInfoEntities();
 
            LEAFConfig_DocumentDatabases connection = context.LEAFConfig_DocumentDatabases
                .Where(c => c.DatabaseName == keyExtension)
                .First();
 
            Log.Information("LEAF_DataKeyResolver""GetConnectionString", connection.ConnectionString);
 
            return connection.ConnectionString;
        }
        catch (Exception ex)
        {
            Log.Error("LEAF_DataKeyResolver""GetConnectionString", ex.Message);
            return "";
        }
 
    }



Replies:
Posted By: katit
Date Posted: 21-Sep-2011 at 1:58pm
I just went through this with IdeaBlade support. Tried to do exact same thing. And their code sample shows how you get connection string using regular EF4 context :)
 
This is response I got:
 
I'd suggest that instead of trying this approach, you actually created the EM after entering the login information.
i.e.
1) Login UI: user enters accountID, username, and password. Click login.
2) create EM: var manager = new IDATTApplicationEntities(true, accountID);
3) login: manager.LoginAsync(credentials);

Basically, after you figure out that you need to pass blank EM into constructor you will get into limitation where your DataSourceKeyResolver won't get keyExtension


Posted By: rickadams
Date Posted: 23-Sep-2011 at 1:14pm
believe I have come up with a solution for the Server side code to do connection string lookup based on the DataSourceKey. However, now when i create my EntityManager in my silverlight client
 
mgrUserConfig = new UserConfigEntities(true,"PROD");
 
it now generates an error "Unable to connect to EntityServer. Unable to start EntityServer_PROD" when it tries to connect. I don't believe this is the documented behaviour. Is this a bug in the 6.1.2 code or am I missing something here.
 
Thanks
 


Posted By: katit
Date Posted: 23-Sep-2011 at 1:22pm
Check debug logs what they say.
Also, when you run this - do you hit breakpoint on your KeyResolver? Do you see "PROD" in there? Do you return proper entity connection string?


Posted By: rickadams
Date Posted: 23-Sep-2011 at 1:48pm
I am not hitting the server at all so there are no log entries on the server side. I get an exception thrown on the Silverlight client. If I remove the DataSourceExtension in the constructor it will connect but of course will not pass the DataSource Extension key


Posted By: rickadams
Date Posted: 26-Sep-2011 at 6:45am
here is my DevForce logfile
 



Print Page | Close Window