• 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=**;")的方式进行连接.

          上一篇  下一偏

  • 相关阅读:
    使用C#直接修改表结构(添加列,删除列)【MS SQL SEVER】
    Nuget-ConsoleExtClass给控制台添加颜色
    Thread线程Join()的使用
    C#将List集合类转换成DataTable-帮助类
    C#动态拼接Linq
    C#使用AutoMapper
    go GOPROXY=http://goproxy.io 设置
    mysql5.6切到5.7(阿里云RDS换到自建库)
    vue学习之----如何在谷歌浏览器中使用vue调试工具
    vue学习之----兄弟组件之间通信方式
  • 原文地址:https://www.cnblogs.com/netcasewqs/p/568320.html
Copyright © 2020-2023  润新知