首页 新闻 会员 周边

请教CS结构的ibatis配置

0
悬赏园豆:20 [已关闭问题] 关闭于 2010-07-23 11:17

我的项目结构如下:
ibaitsTest解决方案下边有四个项目,分别是 model、persistence、service、winform。

其中:

Form1.cs文件:
private string resource = "C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2005\\Projects\\IbatisTest\\WinForm\\dao.config"; 

private void Form1_Load(object sender, EventArgs e)
  {
  DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
  builder.Configure(resource);
  }
Dao.config文件:
<?xml version="1.0" encoding="utf-8"?>
<daoConfig xmlns="http://ibatis.apache.org/dataAccess" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <providers resource="C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\IbatisTest\WinForm\providers.config"/>
  <!--<providers resource="providers.config"/>-->
  <context id="SqlMapDao" default="true">
  <!-- ==== Sql Server : SqlClient configuration ========= -->
  <database>
  <provider name="sqlServer2.0" />
  <dataSource name="SqlServer" connectionString="data source=(local);database=master;user id=sa;password=;" />
  </database>
  <daoSessionHandler id="SqlMap">
  <property name="resource" value="SqlMap.config" />
  </daoSessionHandler>
  <daoFactory>
  <dao interface="IbatisTest.Persistence.ISqlMapDao, IbatisTest.Persistence"
implementation="IbatisTest.Persistence.SqlMapDao, IbatisTest.Persistence" />
  </daoFactory>
  </context>
</daoConfig>
问题1:如果不指定form1中的变量resource,产生的错误是:
Unable to load file via resource "dao.config" as resource. Cause : 未能找到文件“C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\IbatisTest\WinForm\bin\Debug\dao.config”。
为什么会在\bin\debug下找dao.config,而不是在和app.config同一目录下找?

问题2:如果dao.config文件中<providers resource="C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\IbatisTest\WinForm\providers.config"/>,变成
<providers resource="providers.config"/>,错误是:
- The error occurred while Loading Providers config file.

问题3:如果上两个问题都用了绝对路径,则产生的问题是:
- The error occurred while configure DaoSessionHandler.
- The error occurred in <property name="resource" value="SqlMap.config" xmlns="http://ibatis.apache.org/dataAccess" />.  
- Check the IBatisNet.DataAccess.DaoSessionHandlers.SqlMapDaoSessionHandler.

说明:我的dao.config, providers.config,sqlmap.config都放在了winform下边,和app.config在同一目录。

先请教各位达人,怎么解决上述问题。谢谢!

问题补充: 我刚才试过,使用同样的dll文件和方法,开发一个web项目没有问题。我认为主要原因是web.config可以自己找到dao.config、provider.config和sqlmap.config。而app.config却不能找到上述三个文件。请问高手有何解决之道。
相知技术的主页 相知技术 | 初学一级 | 园豆:162
提问于:2010-07-19 17:26
< >
分享
所有回答(2)
0

问题太长了,分有点低哦。

其实问问题也是一门学问

dege301 | 园豆:2825 (老鸟四级) | 2010-07-19 21:54
0

由于编译项目,生成到 ./bin/debug/ 下,执行(run或debug)时都是会从程序执行位置,即你的EXE文件生成位置开始执行,和查找 项目名.exe.config,那当然是从这个旁边找你的Dao.config文件。如果dao文件是手工加入,可以在VS的属性里设置为复制资源,将dao.config复制到生成目录看看。

其实在Web项目中,如果用反射打印一下DLL的执行路径,其实发现也会在/bin目录下,但Web项目由于从浏览器访问的项目路径算起来查找web.config。所以,只要将所有配置文件放在项目文件夹下就可以了。

ERic Poon | 园豆:261 (菜鸟二级) | 2012-09-24 14:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册