New Posts New Posts RSS Feed: DataSourceKeyResolver
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

DataSourceKeyResolver

 Post Reply Post Reply
Author
rickadams View Drop Down
Newbie
Newbie
Avatar

Joined: 04-Mar-2011
Posts: 12
Post Options Post Options   Quote rickadams Quote  Post ReplyReply Direct Link To This Post Topic: DataSourceKeyResolver
    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 "";
        }
 
    }
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
rickadams View Drop Down
Newbie
Newbie
Avatar

Joined: 04-Mar-2011
Posts: 12
Post Options Post Options   Quote rickadams Quote  Post ReplyReply Direct Link To This Post 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
 
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
rickadams View Drop Down
Newbie
Newbie
Avatar

Joined: 04-Mar-2011
Posts: 12
Post Options Post Options   Quote rickadams Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
rickadams View Drop Down
Newbie
Newbie
Avatar

Joined: 04-Mar-2011
Posts: 12
Post Options Post Options   Quote rickadams Quote  Post ReplyReply Direct Link To This Post Posted: 26-Sep-2011 at 6:45am
here is my DevForce logfile
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down