Can anyone shed some light on this problem?

My workaround form yesterday ended up causing me more grief with my ServiceConfig.cs file (which is the same file from the NPetShop application. The following code fails:

protected SqlMapper GetLocalSqlMap()
{
           DaoManager daoManager = DaoManager.GetInstance(this);

SqlMapDaoSession sqlMapDaoSession = (SqlMapDaoSession)daoManager.LocalDaoSession;
           return sqlMapDaoSession.SqlMap;
}

The 2nd context, which I configured with id="ADONET ", ends up having daoManager.LocalDaoSession of type SimpleDaoSession, which can't be cast to (SqlMapDaoSession). I can cast it as (SimpleDaoSession), but that type doesn't have a SqlMap property to return.

I'm sure there must be a better way to configure accessing 2 databases than what I'm doing. Anyone?

Thanks,
Brian


Brian Kierstead wrote:


Well, this isn't exactly what I was looking for, but I came up with a work around of sorts.. If I set the 2nd doaSessionHandler's id="ADONET" (I found this by search the code for SqlMap), it treats them as seperate entities but still recognizes 'resource' as a valid property name.

Brian


Brian Kierstead wrote:

I'm trying to access to seperate database from my application. How do I configure iBatis to do this?

The problem that I'm running into is that when I define 2 <context> sections in my dao.config I'm running into a collosion on the name of the daoSessionHandler id tag.

Here is my dao.config file:
----------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<daoConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="DaoConfig.xsd">

   <providers resource="providers.config" />

   <context id="SqlMapDaoVRL" default="true">
             <properties resource="properties.config" />
         <daoSessionHandler id="SqlMap">
           <property name="resource" value="sqlMapVRL.config"/>
       </daoSessionHandler>
<!-- ==== Sql Server : SqlClient configuration ========= -->
       <database>
           <provider name="sqlServer1.1"/>
           <dataSource name="ShawContractVRL"
               connectionString="
                   data source=${vrl_datasource};
                   database=${vrl_database};
                   user id=${vrl_userid};
                   password=${vrl_password};
                   connection reset=false;
                   connection lifetime=5; min pool size=1;
                   max pool size=50"
           />
       </database>                <daoFactory>
           <dao
interface="ShawCollections.Persistence.Interfaces.Collections.ICollectionDao, ShawCollections.Persistence" implementation="ShawCollections.Persistence.SqlMapDao.Collections.CollectionSqlDao, ShawCollections.Persistence"/>
           <dao
interface="ShawCollections.Persistence.Interfaces.SavedLayouts.ISavedLayoutDao, ShawCollections.Persistence" implementation="ShawCollections.Persistence.SqlMapDao.SavedLayouts.SavedLayoutSqlDao, ShawCollections.Persistence"/>
       </daoFactory>
   </context>

   <context id="SqlMapDaoPS">
             <properties resource="properties.config" />
         <daoSessionHandler id="SqlMap">
<property name="resource" value="sqlMapProductSearch.config"/>
       </daoSessionHandler>
<!-- ==== Sql Server : SqlClient configuration ========= -->
       <database>              <provider name="sqlServer1.1"/>
           <dataSource name="ProductSearch"
               connectionString="
                   data source=${ps_datasource};
                   database=${ps_database};
                   user id=${ps_userid};
                   password=${ps_password};
                   connection reset=false;
                   connection lifetime=5; min pool size=1;
                   max pool size=50"
           />
       </database>
             <daoFactory>
           <dao
interface="ShawCollections.Persistence.Interfaces.Collections.IInstallationDao, ShawCollections.Persistence" implementation="ShawCollections.Persistence.SqlMapDao.Collections.InstallationSqlDao, ShawCollections.Persistence"/>
       </daoFactory>
   </context>
</daoConfig>
----------------------------------------------------------------------------------------------------------------------

When I set the id property in
       <daoSessionHandler id="SqlMap">

to anything other than "SqlMap" (ie. to my own made up id), the application throws an error when it parses name='resource'. If I set them both to the same id (SqlMap) they seem to overwrite each other so that when I try to use the daoManager loaded from the first context (SqlMapDaoVRL) it contains that maps and results of the second context (SqlMapDaoPS).

Is there signifigance to the id that is used? In the docs (section 3.3.3.3 in DataAccess-doc-1.6.1.chm) it says that its "Id used to uniquely identify the handler", but this doesn't seem to be the case.

I assume that I'm doing something wrong in my approach to making 2 databases work. I've looked through the docs and the archives and cobbled what I have here together from those.

Can anyone shed some light on this?

Thanks!
Brian





Reply via email to