• Ndo 配置


             Ndo 的配置方式非常灵活,可以有如下的几种方式
       
             1: 默认的配置方式-单数据库(支持解析SqlClientDriver,OledbDriver,OracleClientDriver,JetDriver,OdbcDriver,SqlOledbDriver,OracleOledbDriver,如果是其它数据源可以通过后面的其它方式)Ndo自动在appSettings 的配置节中找key= "ConnectionString"的配置项,然后进行加载,如果找不到就会抛异常.

                    配置Access数据库(默认)

    <appSettings>
            
    <add key="ConnectionString" value="Data Source=localhost; Database=Northwind; Integrated Security=true;"/>
            
    <add key="JetConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb;"/>
            
    <add key="OracleConn" value="Provider=MSDAORA.1;Data Source=***;User ID=***;Password=***;"/>
            
    <add key= "SqlOledb" value="Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;User ID=sa;Password=;"/>
            
    <add key="Oracle" value="Data Source=***;User ID=***;Password=***;"/>
    </appSettings>

                    用NdoManager 连接数据库

    INdoManager nm = NdoManager.Instance;
    INdoManager nm2 = NdoManager.GetInstance(ConfigurationSettings.AppSettings["SqlOledb"]);


           2: 显式的配置数据驱动器(针对SqlClientDriver,OledbDriver,OracleClientDriver,OdbcDriver,SqlOledbDriver,OracleOledbDriver这几种驱动可以不需要配置数据库方言,NDO内部自动会加载与之相关的数据库方言)
             配置项有:
                               name: 提供者名称(必须)
                               type : 数据驱动器类型(必须)
                               dialect : 数据库方言类型(可选)
                               dataSource:指的是appSettings配置节中配置项的建名
                               connectionString: 数据库连接字符串,如果同时配置了dataSource和connectionString,系统会选择后者
                               commandTimeout:命令超时(可选),默认30秒
                               isEnableParamCache: 是否使用参数缓冲(可选),默认true
                               autoClose: 是否自动关闭连接(可选) ),默认true
         
           

    <configSections>
            
    <section name="ndo" type="Ndo.Configuration.ProviderConfigurationHandler, Ndo"/>
    </configSections>

                配置SqlServer数据库(直连)

    <ndo defaultProvider="sqlClient">
            
    <providers>
                
    <clear/>
                
    <add 
                        
    name="sqlClient" 
                        type
    ="Ndo.Driver.SqlClientDriver,Ndo"
     
                       connectionString = "Data Source=localhost; Database=Pubs; Integrated Security=true;"/>
            
    </providers>
        
    </ndo>

                    用NdoManager 连接数据库

    INdoManager nm = NdoManager.Instance;



          配置SqlServer数据库(通过Oledb连接)

    <ndo defaultProvider="sqlOledb">
            
    <providers>
                
    <clear/>
                
    <add 
                        
    name="sqlOledb" 
                        type
    ="Ndo.Driver.SqlOledbDriver,Ndo"
                        dialect 
    ="Ndo.MsSql2000Dialect,Ndo"
                        dataSource 
    = "SqlOledb"
                        
    />
            
    </providers>
    </ndo>



          配置Access数据库

        <ndo defaultProvider="Jet">
            
    <providers>
                
    <clear/>
                
    <add 
                        
    name="Jet" 
                        type
    ="Ndo.Driver.JetDriver,Ndo"
                        dialect 
    ="Ndo.MsAccessDialect,Ndo"
                        dataSource 
    = "JetConnectionString"
                        
    />
            
    </providers>
        
    </ndo>

          配置Oracle 数据库(直连)

    <ndo defaultProvider="oracleClient">
            
    <providers>
                
    <clear/>
                
    <add 
                        
    name="oracleClient" 
                        type
    ="Ndo.Driver.OracleClientDriver,Ndo"
                        dataSource 
    = "Oracle"
                        
    />
            
    </providers>
    </ndo>

         配置Oracle 数据库(通过Oledb,不建议,速度慢)

    <ndo defaultProvider="oracleOledb">
            
    <providers>
                
    <clear/>
                
    <add 
                        
    name="oracleOledb" 
                        type
    ="Ndo.Driver.OracleOledbDriver,Ndo"
                        dialect 
    ="Ndo.OracleDialect,Ndo"
                        dataSource 
    = "OracleConn"/>
            
    </providers>
    </ndo>


            前面的配置都是单数据库,那么多数据库的配置请看下面:

    <ndo defaultProvider="sqlClient">
            
    <providers>
                
    <clear/>
                
    <add 
                        
    name="sqlClient" 
                        type
    ="Ndo.Driver.SqlClientDriver,Ndo"
                        dataSource 
    = "ConnectionString"/>
                
    <add 
                        
    name="oracleClient" 
                        type
    ="Ndo.Driver.OracleClientDriver,Ndo"
                        dataSource 
    = "Oracle"/>
            
    </providers>
    </ndo>

           

                    用NDOManager 连接数据库

    INdoManager sqlClient = NdoManager.Instance;
       INdoManager oracle = NdoManager.Config("oracleClient");


          最后如果没有配置,可以用INdoManager nm = NdoManager.GetInstance("server=localhost;database=northwind;user=sa;password=**;")的方式进行连接.

          上一篇  下一偏

  • 相关阅读:
    swjtu oj Paint Box 第二类斯特林数
    B -- RE:从零开始的异世界生活 线段树
    EOJ Problem #3261 分词 trie + dp + 小剪枝
    129. 笔芯值
    F. Coprime Subsequences 莫比乌斯反演
    F. Clique in the Divisibility Graph DP
    D. Restructuring Company 并查集 + 维护一个区间技巧
    scut 125. 笔芯回文
    几个链接
    位处理的低级筛法
  • 原文地址:https://www.cnblogs.com/netcasewqs/p/568320.html
Copyright © 2020-2023  润新知