You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Randall Svancara <rs...@cableone.net> on 2006/03/26 14:30:30 UTC

C# .Net 2.0

I am struggling to implement Ibatis in a windows based application.  I 
have followed the NPetShop tutorial as an example.  I have no problem 
implementing IBatis in my Java based applicaitons. 

I keep recieving an error:

System.TypeInitializationException: The type initializer for 
'Test.Service.RecruiterService' threw an exception. ---> 
System.NullReferenceException: Object reference not set to an instance 
of an object.
   at Test.Service.RecruiterService..ctor() in 
C:\source\TEST\TEST\Test.Service\RecruiterService.cs:line 47
   at Test.Service.RecruiterService..cctor() in 
C:\source\TEST\TEST\Test.Service\RecruiterService.cs:line 17
   --- End of inner exception stack trace ---
   at Test.Service.RecruiterService.GetInstance()
   at Test.Client.Form1.button1_Click(Object sender, EventArgs e) in 
C:\source\TEST\TEST\Test.Client\Form1.cs:line 32
A first chance exception of type 'System.TypeInitializationException' 
occurred in Test.Client.exe
The thread 'Win32 Thread' (0xadc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x35c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xf1c) has exited with code 0 (0x0).
The program '[2424] Test.Client.exe: Managed' has exited with code 0 (0x0).
The program '[2424] Test.Client.exe: Native' has exited with code 0 (0x0).

My guess, based on the error is something is not being initialized 
properly.  I have implemented a dao.config, a SqlMap.config, 
providers.config and I have a Recruiter.xml.

All these files are placed into the Debug directory from which the 
application executes from.

dao.config:

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

  <context name="SqlMapDao">
    <daoSessionHandler name="SqlMap">
      <property name="sqlMapConfigFile" value="sqlMap.config"/>
    </daoSessionHandler>

    <!-- ==== Sql Server : SqlClient configuration ========= -->
        <database>
            <provider name="sqlServer1.1"/>
          <dataSource name="SummitExecProd" connectionString="data 
source=(local)\NetSDK;database=test;user 
id=sa;password=dofa7h;connection reset=false;connection lifetime=5; min 
pool size=1; max pool size=50"/>
        </database>

    <daoFactory assembly="NPetshop.Persistence.dll">
      <dao name="Recruiter"
                
implementation="Test.Persistence.MapperDao.Recruiter.RecruiterSqlMapDao"/>
    </daoFactory>
  </context>

</daoConfig>


sqlMap.config

<?xml version="1.0" encoding="utf-8"?>
<sqlMapConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="SqlMapConfig.xsd">
    <settings>
        <setting useStatementNamespaces="false"/>
        <setting cacheModelsEnabled="true"/>
    </settings>
           
    <!-- ==== SqlClient configuration =========    -->
    <!-- Optional ( default ) -->
    <!-- Rem : If used with a Dao it will be ignored -->
    <database>
        <provider name="sqlServer1.1"/>
        <dataSource name="SummitExecProd" connectionString="data 
source=(local)\NetSDK;database=test;user 
id=sa;password=dofa7h;connection reset=false;connection lifetime=5; min 
pool size=1; max pool size=50"/>
    </database>

    <sqlMaps>
        <sqlMap resource="Maps\Recruiter.xml"/>

    </sqlMaps>
   
</sqlMapConfig>


I have created the Service, Persistance and Domain classes just like the 
NPetshop example.  In the ServiceConfig.cs , the instance.daoManager is 
null.  How can I tell what is causing this error.  How do I enable more 
verbose logging for debugging purposes.

Thanks,

Randall


 

Re: Can SelectKey have a parameter

Posted by Ron Grabowski <ro...@yahoo.com>.
The InsertDeSerializer class only looks for property, type, and
resultClass attributes. I've added an issue along with a patch in Jira
for selectKey nodes to allow dynamic sql:

 http://issues.apache.org/jira/browse/IBATISNET-143

I suppose InsertDeSerializer could be changed to allow a
parameterMap...you should be using the selectKey node to do simple
things like:

 SELECT SCOPE_IDENTITY()

--- Eka Gautama <ek...@seatech.com> wrote:

> Hi all,
> 
> Is it possible a <SelectKey> element has a parameterMap? Any samples
> please 
> :)
> 
> Regards
> 
> Eka 
> 
> 


Can SelectKey have a parameter

Posted by Eka Gautama <ek...@seatech.com>.
Hi all,

Is it possible a <SelectKey> element has a parameterMap? Any samples please 
:)

Regards

Eka 


Re: C# .Net 2.0

Posted by Randall Svancara <rs...@cableone.net>.
Nevermind,

I was using the old provider.config file from the original NPetshop.  I 
have to say that it is terribly outdated.

Thanks,

Randall

Randall Svancara wrote:

> Ron,
>
> Thank you for all your help.  I implemented your suggestions and found 
> the online subversion repository great help.
>
> I have Log4net working.  The configuration looks like this in my 
> app.config:
>
>  <configSections>
>    <sectionGroup name="iBATIS">
>      <section name="logging" 
> type="IBatisNet.Common.Logging.ConfigurationSectionHandler, 
> IBatisNet.Common" />
>    </sectionGroup>  </configSections>
>
>  <iBATIS>
>    <logging>
>      <logFactoryAdapter 
> type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,IBatisNet.Common.Logging.Log4Net"> 
>
>          <arg key="configType" value="file" />
>          <arg key="configFile" value="Log4Net.config" />
>        </logFactoryAdapter>
>      </logging>
>    </iBATIS>
>
> Although this is a simple test that I am creating, I want to use the 
> DAO components in case I have multiple datasources.  Plus I think it 
> is just good practice to have a good DAO framework to make things 
> cleaner.  Hence the reason I went with Ibatis in the first place.
> One small problem yet remains however.  I am receiving an error:
>
> {"\n- The error occurred while configure provider.\n- The error 
> occurred in <provider name=\"sqlServer1.1\" 
> xmlns=\"http://ibatis.apache.org/dataAccess\" />.  \n- Check the 
> sqlServer1.1."}
>
> In my dao.config, I have this:
>
> <?xml version="1.0" encoding="utf-8"?>
> <daoConfig  xmlns="http://ibatis.apache.org/dataAccess"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
>  <context id="SqlMapDao" default="true">
>
>
>    <!-- ==== Sql Server : SqlClient configuration ========= -->
>        <database>
>      <provider name="sqlServer1.1"/>
>            <dataSource name="SqlServer" connectionString="data 
> source=(local)\NetSDK;database=TEST;user 
> id=sa;password=dofa7h;connection reset=false;connection lifetime=5; 
> min pool size=1; max pool size=50"/>
>        </database>
>
>
>    <daoSessionHandler id="SqlMap">
>      <property name="sqlMapConfigFile" value="sqlMap.config"/>
>    </daoSessionHandler>
>
>    <daoFactory>
>      <dao interface="Test.Persistance.Interface.Accounts.IAccountDao"
>                    
> implementation="Test.Persistence.Dao.Accounts.AccountDao,Test.Persistence.Dao.Accounts"/> 
>
>    </daoFactory>
>  </context>
>
> </daoConfig>
>
>
> I can not figure out why the provider portion does not work 
> correctly.  I am using visual studio 2005 with the .net 2.0 
> framework.   My application is a windows based application.  I will 
> eventually be refactoring an application that i support with IBATIS 
> .Net.  Any help anyone has would be appreciated.
> I hope to eventually publish my code online to help others with the 
> same struggles i have....the beauty of open source!!!!
>
>
>
> Ron Grabowski wrote:
>
>> Once the project builds and loads correctly, you may want to use
>> Log4Net instead of the built-in logging facilities. This is what your
>> iBATIS/logging node might look like:
>>
>> <iBATIS>
>> <logging>
>>  <logFactoryAdapter type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
>> IBatisNet.Common.Logging.Log4Net">
>>   <arg key="configType" value="external" />
>>  </logFactoryAdapter>
>> </logging>       
>> </iBATIS>
>>
>> You'll need to put these two files in your bin directory:
>>
>> log4net.dll
>> IBatisNet.Common.Logging.Log4Net.dll
>>
>> By setting the configType to external, your application is responsible
>> for initializing Log4Net. Here's a link to the Log4Net website:
>>
>> http://logging.apache.org/log4net/
>>
>> --- Ron Grabowski <ro...@yahoo.com> wrote:
>>
>>  
>>
>>> IBatisNet supports a pluggable logging arhcitecture. I (most people?)
>>> use Log4Net. Here's an untested config file that routes log messages
>>> to
>>> System.Diagnostics.Trace which is routed to a text file.
>>>   
>>
>>
>>  
>>
>
>


Re: C# .Net 2.0

Posted by Randall Svancara <rs...@cableone.net>.
Ron,

Thank you for all your help.  I implemented your suggestions and found 
the online subversion repository great help.

I have Log4net working.  The configuration looks like this in my app.config:

  <configSections>
    <sectionGroup name="iBATIS">
      <section name="logging" 
type="IBatisNet.Common.Logging.ConfigurationSectionHandler, 
IBatisNet.Common" />
    </sectionGroup> 
  </configSections>
 
  <iBATIS>
    <logging>
      <logFactoryAdapter 
type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,IBatisNet.Common.Logging.Log4Net">
          <arg key="configType" value="file" />
          <arg key="configFile" value="Log4Net.config" />
        </logFactoryAdapter>
      </logging>
    </iBATIS>

Although this is a simple test that I am creating, I want to use the DAO 
components in case I have multiple datasources.  Plus I think it is just 
good practice to have a good DAO framework to make things cleaner.  
Hence the reason I went with Ibatis in the first place. 

One small problem yet remains however.  I am receiving an error:

{"\n- The error occurred while configure provider.\n- The error occurred 
in <provider name=\"sqlServer1.1\" 
xmlns=\"http://ibatis.apache.org/dataAccess\" />.  \n- Check the 
sqlServer1.1."}

In my dao.config, I have this:

<?xml version="1.0" encoding="utf-8"?>
<daoConfig  xmlns="http://ibatis.apache.org/dataAccess"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <context id="SqlMapDao" default="true">


    <!-- ==== Sql Server : SqlClient configuration ========= -->
        <database>
      <provider name="sqlServer1.1"/>
            <dataSource name="SqlServer" connectionString="data 
source=(local)\NetSDK;database=TEST;user 
id=sa;password=dofa7h;connection reset=false;connection lifetime=5; min 
pool size=1; max pool size=50"/>
        </database>


    <daoSessionHandler id="SqlMap">
      <property name="sqlMapConfigFile" value="sqlMap.config"/>
    </daoSessionHandler>

    <daoFactory>
      <dao interface="Test.Persistance.Interface.Accounts.IAccountDao"
                    
implementation="Test.Persistence.Dao.Accounts.AccountDao,Test.Persistence.Dao.Accounts"/>
    </daoFactory>
  </context>

</daoConfig>


I can not figure out why the provider portion does not work correctly.  
I am using visual studio 2005 with the .net 2.0 framework.   My 
application is a windows based application.  I will eventually be 
refactoring an application that i support with IBATIS .Net.  Any help 
anyone has would be appreciated. 

I hope to eventually publish my code online to help others with the same 
struggles i have....the beauty of open source!!!!



Ron Grabowski wrote:

>Once the project builds and loads correctly, you may want to use
>Log4Net instead of the built-in logging facilities. This is what your
>iBATIS/logging node might look like:
>
><iBATIS>
> <logging>
>  <logFactoryAdapter 
>type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
>IBatisNet.Common.Logging.Log4Net">
>   <arg key="configType" value="external" />
>  </logFactoryAdapter>
> </logging>		
></iBATIS>
>
>You'll need to put these two files in your bin directory:
>
> log4net.dll
> IBatisNet.Common.Logging.Log4Net.dll
>
>By setting the configType to external, your application is responsible
>for initializing Log4Net. Here's a link to the Log4Net website:
>
> http://logging.apache.org/log4net/
>
>--- Ron Grabowski <ro...@yahoo.com> wrote:
>
>  
>
>>IBatisNet supports a pluggable logging arhcitecture. I (most people?)
>>use Log4Net. Here's an untested config file that routes log messages
>>to
>>System.Diagnostics.Trace which is routed to a text file.
>>    
>>
>
>  
>


Re: C# .Net 2.0

Posted by Ron Grabowski <ro...@yahoo.com>.
Once the project builds and loads correctly, you may want to use
Log4Net instead of the built-in logging facilities. This is what your
iBATIS/logging node might look like:

<iBATIS>
 <logging>
  <logFactoryAdapter 
type="IBatisNet.Common.Logging.Impl.Log4NetLoggerFA,
IBatisNet.Common.Logging.Log4Net">
   <arg key="configType" value="external" />
  </logFactoryAdapter>
 </logging>		
</iBATIS>

You'll need to put these two files in your bin directory:

 log4net.dll
 IBatisNet.Common.Logging.Log4Net.dll

By setting the configType to external, your application is responsible
for initializing Log4Net. Here's a link to the Log4Net website:

 http://logging.apache.org/log4net/

--- Ron Grabowski <ro...@yahoo.com> wrote:

> IBatisNet supports a pluggable logging arhcitecture. I (most people?)
> use Log4Net. Here's an untested config file that routes log messages
> to
> System.Diagnostics.Trace which is routed to a text file.

Re: C# .Net 2.0

Posted by Ron Grabowski <ro...@yahoo.com>.
--- Randall Svancara <rs...@cableone.net> wrote:

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

NPetshop is very old. This is the correct daoConfig node:

<daoConfig  xmlns="http://ibatis.apache.org/dataAccess" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

>     <daoFactory assembly="NPetshop.Persistence.dll">
>       <dao name="Recruiter"
>                 
>
implementation="Test.Persistence.MapperDao.Recruiter.RecruiterSqlMapDao"/>
>     </daoFactory>

<daoFactory>
 <dao 
  interface="Foo.Data.IAccountDao, Foo.Data" 
  implementation="Foo.Data.SqlMapDao.AccountDao, Foo.Data.SqlMapDao"/>
</daoFactory>

> <?xml version="1.0" encoding="utf-8"?>
> <sqlMapConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:noNamespaceSchemaLocation="SqlMapConfig.xsd">

<sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

> I have created the Service, Persistance and Domain classes just like
> the 
> NPetshop example.  In the ServiceConfig.cs , the instance.daoManager
> is 
> null.  How can I tell what is causing this error.  How do I enable
> more 
> verbose logging for debugging purposes.

If you're using a single database, you probably don't need the
DataAccess component. If that's the case, you just need
Providers.config and SqlMap.config.

IBatisNet supports a pluggable logging arhcitecture. I (most people?)
use Log4Net. Here's an untested config file that routes log messages to
System.Diagnostics.Trace which is routed to a text file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
  <sectionGroup name="iBATIS">
   <section 
    name="logging" 
    type="IBatisNet.Common.Logging.ConfigurationSectionHandler,
IBatisNet.Common" />
  </sectionGroup>	
 </configSections>
 <iBATIS>
  <logging>
   <logFactoryAdapter
type="IBatisNet.Common.Logging.Impl.TraceLoggerFA, IBatisNet.Common">
    <arg key="logLevel" value="All" />
    <arg key="showDateTime" value="true" />
    <arg key="showLogName" value="true" />
   </logFactoryAdapter>
  </logging>		
 </iBATIS>
 <system.diagnostics>
  <trace autoflush="true">
   <listeners>
    <add name="textWriterTraceListener" 
     type="System.Diagnostics.TextWriterTraceListener"
     initializeData="C:\\IBatisNetLog.txt" />
   </listeners>
  </trace>
 </system.diagnostics>
</configuration>

This is a good place to look for up to date example code:

http://tinyurl.com/n3g4m
http://svn.apache.org/viewcvs.cgi/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test

- Ron