保存NHibernate配置xml文件信息的源代码

<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("保存出错,请重新保存操作!", "提示");
                        } 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值