保存NHibernate配置xml文件信息的源代码
2015-04-01 00:03
423 查看
<pre name="code" class="html"><pre code_snippet_id="632860" snippet_file_name="blog_20150401_1_8801928" name="code" class="csharp">hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory name="CwfServer"> <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property> <property name="dialect">NHibernate.Dialect.MySQLDialect</property> <property name="connection.connection_string">Server=114.80.156.207;Database=sq_locationinfo;Uid=sq_locationinfo;Pwd=hbc771215;</property> <property name="default_schema"></property> <property name="adonet.batch_size">10</property> <property name="show_sql">true</property> <property name="command_timeout">60</property> <property name="hbm2ddl.auto">update</property> <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> <mapping assembly="LNFrameWork" /> </session-factory> </hibernate-configuration>
//保存NHibernate配置xml文件信息 string nh_xmlconfigPath = Application.StartupPath + "\\Config\\hibernate.cfg.xml"; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(nh_xmlconfigPath); XmlNodeList hc_node = xmldoc.ChildNodes; XmlNodeList sf_node = hc_node[1].ChildNodes; XmlNodeList propList = sf_node[0].ChildNodes;// SelectNodes("hibernate-configuration/session-factory/property"); if (propList != null) { foreach (XmlNode propNode in propList) { if (propNode.Attributes["name"] != null) { string name = propNode.Attributes["name"].Value; #region //通过Attributes获得属性名字为name的属性 switch (name) { case "connection.driver_class": switch (this.ucConnInfo.DatabaseType) { case DataProviderType.Sql: propNode.InnerText = typeof(SqlClientDriver).FullName; break; case DataProviderType.Oracle: propNode.InnerText = typeof(OracleClientDriver).FullName; break; case DataProviderType.MySQL: propNode.InnerText = typeof(MySqlDataDriver).FullName; break; } break; case "dialect": switch (this.ucConnInfo.DatabaseType) { case DataProviderType.Sql: propNode.InnerText = typeof(MsSql2008Dialect).FullName; break; case DataProviderType.Oracle: propNode.InnerText = typeof(Oracle10gDialect).FullName; break; case DataProviderType.MySQL: propNode.InnerText = typeof(MySQL5Dialect).FullName; break; } break; case "connection.connection_string": propNode.InnerText = this.ucConnInfo.ConnInfo; break; case "default_schema": propNode.InnerText = this.ucConnInfo.dbname_userid; break; } #endregion } } } xmldoc.Save(nh_xmlconfigPath); xmldoc.Save(nh_xmlconfigPath); xmldoc = new XmlDocument(); xmldoc.Load(nh_xmlconfigPath); if (xmldoc.OuterXml.Contains(this.ucConnInfo.ConnInfo) == true) { MessageBox.Show("保存完毕!", "提示"); } else { MessageBox.Show("保存出错,请重新保存操作!", "提示"); }
相关文章推荐
- 使用Spring中Src下 -context.xml : 用资源文件夹保存数据库的链接信息 并在配置文件里读取
- NHibernate 配置文件的处理和使用多数据库的多层架构思路(第三部分,附源代码)
- 使用XML保存程序需要的配置信息
- 利用jConfig获取xml文件中的配置信息
- 使用xml配置文件配置DataGridView的列信息
- 保存类中变量或属性到XML配置文件
- 在PDA程序中使用XML文件保存程序配置设置
- INI的替代品--XML配置文件读取与保存
- JAVA中读取XML文件中的配置信息
- NHibernate.xml 的配置文件
- 在web.xml文件中配置信息,未起作用问题解决
- 代码怎样引用plug-in.xml, menifest.mf等配置文件的信息
- 总结:NHibernate——配置文件hibernate.cfg.xml
- 如何配置NHibernate的XML配置文件的智能感知(IntelliSense)功能 ?
- 保存类中变量或属性到XML配置文件
- 条码手持设备对XML配置文件的获取与更新保存(条码系列二)
- jbpm.cfg.xml文件配置的源代码:
- NHibernate开发技巧:为hbm.xml配置文件添加智能提示(VS2008)
- 利用Jakarta Commons Digester匹配xml配置文件信息与其对应的xml规则文件形成Java Object
- 保存类中变量或属性到XML配置文件