New Posts New Posts RSS Feed: Peeking into several databases of the same type
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Peeking into several databases of the same type

 Post Reply Post Reply
Author
jcdk View Drop Down
Newbie
Newbie


Joined: 25-Aug-2007
Location: Denmark
Posts: 11
Post Options Post Options   Quote jcdk Quote  Post ReplyReply Direct Link To This Post Topic: Peeking into several databases of the same type
    Posted: 12-Jun-2008 at 6:39am
Hi,
 
I have a question about the persistence manager: I need to peek into several databases, all with the same schema and all mapped with the same model.dll before I decide wich one to use in my application. I have created my own DataSourceKeyResolver which returns a different connection string based on an entry in the registry. Simplified what I do is this:
 

Dim aEmployee As Employee

Dim EmployeeQuery As New EntityQuery(GetType(Employee))

Registry.SetValue("HKEY_CURRENT_USER\SOFTWARE\DimensionProject", "DataBase", "DP1")

'The line above instructs the datasourcekeyresolver to return a connection string to DP1
 
PersMgr = PersistenceManager.DefaultManager

EmployeeQuery.AddClause(Employee.EmployeeCodeEntityColumn, EntityQueryOp.EQ, "JC")

aEmployee = PersMgr.GetEntity(Of Employee)(EmployeeQuery)

MsgBox(aEmployee.Name)

'This shows data from DP1
 
PersMgr.QueryCache.Clear()

Dim pEntityTables As DataTableCollection = PersMgr.DataSet.Tables

Dim anEntityTable As DataTable

For Each anEntityTable In pEntityTables

ClearEntityTable(anEntityTable)

Next

PersMgr.Clear()

Registry.SetValue("HKEY_CURRENT_USER\SOFTWARE\DimensionProject", "DataBase", "DP2")

'Datasourcekeyresolver to return connection string to DP2. If I break the program in the
'keyresolver it DOES get called when I create the persistencemanager in th next line,
'and it DOES return the correct connectionstring
 
PersMgr = New PersistenceManager(True)

EmployeeQuery.AddClause(Employee.EmployeeCodeEntityColumn, EntityQueryOp.EQ, "JC")

aEmployee = PersMgr.GetEntity(Of Employee)(EmployeeQuery, QueryStrategy.DataSourceOnly)

MsgBox(aEmployee.Name)

'This still shows me data from DP1

If I "quickwatch" the peristencemanager and look at PersMgr.DataSourceResolver.mDataSourceResolver.DataSourceKeys.Items(0) it shown the correct connectionstring to DP2, but I still get data from DP1.
Am I missing a point somewhere or is it not possible to do something like this?
 
Best regards
Jesper Carstensen
Back to Top
jcdk View Drop Down
Newbie
Newbie


Joined: 25-Aug-2007
Location: Denmark
Posts: 11
Post Options Post Options   Quote jcdk Quote  Post ReplyReply Direct Link To This Post Posted: 13-Jun-2008 at 1:04am
Hi All
 
I solved it myself by rewriting my code.
 
I created an array of PersistenceManagers, each created with a different DatasourceKeyExtension (equal to the database name). I also modified my DataSourceKeyResolver to return a dfferent connection string for each DataSourceKeyExtension.
 
Now I can connect and disconnect the PersistenceManagers as I need them.
 
Best regards
Jesper Carstensen
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 13-Jun-2008 at 7:36am
Jesper.
 
That is the correct technique.  You must have different and unique DataSourceKeyExtensions.  Then the DataSourceKeyResolver should return a different connection string for each DataSourceKeyExtension.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down