• SQL Server改MySQL注意事项


    主要是NHibernate连接MySQL注意事项:

    1. 在website的bin目录里添加MySql.Data.dll(可在官方下载)和hibernate.cfg.xml
    2. 启用新的OpenSession()方法
    3. 通过ADO连接数据库的方式会出现“用户名root无法登陆”的错误提示。所以全部通过NHibernate连接,使用NHibernate的函数。
    4. 在电脑上安装MySql的时候注意选择“Developer Machine”.要不然会出现无法启动MySql服务的错误:
    5. T-SQL和MySql一些常见的不兼容。
      • top 10 -> limit index,length
      • dbo. -> 空
      • getDate() -> NOW()
      • DATEADD(mi,15,GETDATE()) -> DATE_ADD(NOW(), INTERVAL 15 MINUTE)
      • .....

    参考:

      1. hibernate.cfg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!--
    This template was written to work with NHibernate.Test.
    Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
    for your own use before compile tests in VisualStudio.
    -->
    <!-- This is the ByteFX.Data.dll provider for MySql -->
    <hibernate-configuration  xmlns="urn:nhibernate-configuration-2.0" >
        <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
            <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
            <property name="connection.connection_string">
                Database=clientsystem_dbo;Data Source=127.0.0.1;User Id=root;Password=123456
            </property>
        
        <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
            <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>  
        <property name="hbm2ddl.keywords">none</property>

      </session-factory>
    </hibernate-configuration>

    1. OpenSession()       //MySql 初始化session配置
              public static ISession OpenSession()
              {
                  try
                  {
                      ISession session = null;
                      if (m_factory == null)
                      {
                          m_factory = m_cfg.Configure().Configure().AddAssembly(AssemblyClassName).BuildSessionFactory();
                          session = m_factory.OpenSession();
                      }
                      else
                      {
                          session = m_factory.OpenSession();
                      }
                      return session;
                  }
                  catch (Exception e)
                  {
                      return null;
                      throw e;
                  }
              }
  • 相关阅读:
    Python基础总结之第三天开始重新认识‘字符串’(新手可相互督促)
    Python基础总结之第二天从变量开始(新手可相互督促)
    Python基础总结之第一天(新手可相互督促)
    简析 Golang IO 包
    简析 Golang net/http 包
    Elasticsearch Query DSL 语言介绍
    Golang Context 包详解
    解读 kubernetes client-go 官方 examples
    ACM学习之路___HDU 1385(带路径保存的 Floyd)
    ACM学习之路___HDU 2066 一个人的旅行
  • 原文地址:https://www.cnblogs.com/Liao/p/2142787.html
Copyright © 2020-2023  润新知