<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Help for Multiple Datasources</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce Classic : Help for Multiple Datasources</description>
  <pubDate>Sun, 12 Apr 2026 02:28:45 -700</pubDate>
  <lastBuildDate>Thu, 12 Jul 2007 15:20:11 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=195</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Help for Multiple Datasources : When the OM generates business...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=195&amp;PID=429#429</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=21" rel="nofollow">IdeaBlade</a><br /><strong>Subject:</strong> 195<br /><strong>Posted:</strong> 12-Jul-2007 at 3:20pm<br /><br /><P =Ms&#111;normal><FONT color=navy size=3><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><SPAN =325090320-02042007>When the OM generates business object classes, it "stamps" them with the DataSourceKeyName specified in the Object Mapper. (It's the value in the "Key" column in the "Data Source Keys" grid.)&nbsp; Since your DBa and DBb databases have the same structure, you could use either of them for your design-time work.&nbsp; So, in the Object Mapper, you would add a second row to the Data Source Keys grid.&nbsp; You would point the first row to database DB1, and the second to DBa (or DBb, or any other database with the same structure).&nbsp;&nbsp; </SPAN></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT color=navy size=3><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007></SPAN></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT size=3><FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>When you instantiate a PersistenceManager (to retrieve and save objects), you can specify a DataSourceExtension (string).&nbsp; (If you don't specify one, it gets an extension consisting of an empty string.) Then when you ask that PM to retrieve some objects, it finds or creates a DataSourceKey (in memory) object based upon (1) the DataSourceKeyName embedded in the class for the objects of the type to be retrieved, and (2) the DataSourceExtension associated with the PersistenceManager.&nbsp; A DataSourceKeyResolver uses a method, <EM>GetKey(KeyName, KeyExtension) </EM>to find or create this </SPAN></o:p></SPAN></FONT><FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>DataSourceKey object. The object&nbsp;includes the connection string necessary to access a specify physical instance of the database.</SPAN></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal><FONT size=3><FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>For the purpose of discussion, let's say that, in the Data Source Keys grid in the Object Mapper, you leave the name of the key in the DB1 record as "default", but rename the one in the second row from "Key" to "secondary".&nbsp; Then in your code you instantiate a PersistenceManager using a overload of the PersistenceManager's constructor that let's you specify the extension, and that you specify an extension of "B".&nbsp; Then, when attempting to retrieve objects from </SPAN></o:p></SPAN></FONT><FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>your first database, your app would look for a key with a name of "default" and an extension of "".&nbsp; When attempting to retrieve objects from <FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>your second database, your app would look for a key with a name of "secondary" and an extension of "B".&nbsp;&nbsp;In either case, the first request for data from the the first database would result in the creation of one in-memory DataSourceKey object; and the first request for data from the secondary database would result in the creation of a second (and different) in-memory DataSourceKey object. Subsequent requests for data from either database would NOT result in the creation of any more DataSourceKeys; rather, the existing ones would be found and used.</SPAN></o:p></SPAN></FONT></SPAN></o:p></SPAN></FONT></FONT></P><P =Ms&#111;normal><FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><FONT color=navy size=3><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>You actually do not necessary need a custom DataSourceKeyResolver to make this work. If your ibconfig file has proper entries, the default resolver will find the right copy of the second database.&nbsp; The section of your ibconfig file containing RdbKeys, for example, might look like the following:</SPAN></o:p></SPAN></FONT></SPAN></o:p></SPAN></FONT></P><P =Ms&#111;normal><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><FONT size=3>&nbsp; &lt;rdbKey name="default" databaseProduct="Unknown"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;connection&gt;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=<FONT color=#800000>Xyz</FONT>;Data Source=.&lt;/connection&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;probeAssemblyName&gt;Model&lt;/probeAssemblyName&gt;<BR>&nbsp; &lt;/rdbKey&gt;</FONT></SPAN></o:p></SPAN></SPAN></o:p></SPAN></P><P =Ms&#111;normal><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><FONT size=3>&nbsp; &lt;rdbKey name="secondary_A" databaseProduct="Unknown"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;connection&gt;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=<FONT color=#800000>Pdq</FONT>;Data Source=.&lt;/connection&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;probeAssemblyName&gt;Model&lt;/probeAssemblyName&gt;<BR>&nbsp; &lt;/rdbKey&gt;</FONT></P></SPAN></o:p></SPAN></SPAN></o:p></SPAN><P =Ms&#111;normal><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><FONT size=3>&nbsp; &lt;rdbKey name="secondary_B" databaseProduct="Unknown"&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;connection&gt;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=<FONT color=#800000>Abc</FONT>;Data Source=.&lt;/connection&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;probeAssemblyName&gt;Model&lt;/probeAssemblyName&gt;<BR>&nbsp; &lt;/rdbKey&gt;<BR></FONT></P></SPAN></o:p></SPAN></SPAN></o:p></SPAN><P =Ms&#111;normal><FONT color=#000080 size=3><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>The default DataSourceKeyResolver would find the rdbKey entry corresponding to the needed DataSourceKey by concatenating the DataSourceKeyName (obtained from the business object type) and the DataSourceExtension (obtained from the PersistenceManager) and comparing the result to the name specified in the rdbKey.&nbsp; Thus, if your app had instantiated the PM as follows:</SPAN></o:p></SPAN></SPAN></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT color=#000080 size=3><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>&nbsp;&nbsp;&nbsp; ...</SPAN></o:p></SPAN></SPAN></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT color=#000080 size=3><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>&nbsp;&nbsp;&nbsp; datasourceExtensionName = "B";</SPAN></o:p></SPAN></SPAN></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT color=#000080><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><FONT size=3>&nbsp;&nbsp;&nbsp; PersistenceManager pm =&nbsp; new PersistenceManager (true, datasourceExtensionName);</FONT></P><P =Ms&#111;normal><FONT color=#000080 size=3><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>&nbsp;&nbsp;&nbsp; ...</SPAN></o:p></SPAN></SPAN></o:p></SPAN></FONT></P><P =Ms&#111;normal></SPAN></o:p></SPAN></SPAN></o:p></SPAN></FONT><FONT size=3><FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>then, while attempting the first retrieval of&nbsp;objects of a type sourced in the <EM>secondary </EM>database, it would create a DataSourceKey using information mined out of the third rdbKey entry above.&nbsp; It would therefore access the database named "Abc".&nbsp; Any subsequent request to access data in the same database would use the in-memory DataSourceKey object created for this first access; that is, DevForce would not go back to the ibconfig file.</SPAN></o:p></SPAN></FONT><FONT face="Times New Roman">&nbsp;</FONT></FONT></P><P =Ms&#111;normal><FONT size=3><FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>The best source of further information about this is probably the section "</SPAN></o:p></SPAN></FONT><FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007><FONT color=navy><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p><SPAN =325090320-02042007>DevForce and Data Sources – Digging Deeper", in Chapter 4 of the IdeaBlade DevForce Developers Guide.&nbsp; </SPAN></o:p></SPAN></FONT></SPAN></o:p></SPAN></FONT></FONT></P>]]>
   </description>
   <pubDate>Thu, 12 Jul 2007 15:20:11 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=195&amp;PID=429#429</guid>
  </item> 
  <item>
   <title>Help for Multiple Datasources : I start a new project right after...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=195&amp;PID=428#428</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=20" rel="nofollow">Customer</a><br /><strong>Subject:</strong> 195<br /><strong>Posted:</strong> 12-Jul-2007 at 3:18pm<br /><br /><P =Ms&#111;normal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">I start a new project right after the training on your side. My project involves in multiple databases at run time.</SPAN></FONT><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p>&nbsp;</o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">The case is:<o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">I have databases as DB1, DBa, DBb. DB1 has different structure from DBa and DBb, and DBa and DBb have the same structure. <o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">My application will need to connect to DB1 and either DBa or DBb at every runtime base on the database name I pass in dynamically. I follow the training material to write my own custom DataSourceKeyResolvers and add it to the AppHelp project to have the PM point to a desired Datasource.</SPAN></FONT><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p>&nbsp;</o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">My question is how should I use the object mapper to generate the business objects for DB1 and DBa(b)?<o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Do you have a complete example to show more detail of implement the Custom DatasourceKeyresolvers ?&nbsp;</SPAN></FONT><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"><o:p>&nbsp;</o:p></SPAN></FONT></P><P =Ms&#111;normal><FONT face=Arial color=navy size=2><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Or do you have a better approach to handler this case?</SPAN></FONT></P>]]>
   </description>
   <pubDate>Thu, 12 Jul 2007 15:18:58 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=195&amp;PID=428#428</guid>
  </item> 
 </channel>
</rss>