• get all ODBC drivers 驱动


    get all ODBC drivers 驱动:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading;
    
    namespace CSConsoleTest2
    {
        public static class Program
        {
            static void Main()
            {
                var drivers = GetSystemDriverList();
    
                string[] v = new string[4];
                v[0] = "server=127.0.0.1;database=TestData;uid=test;pwd=test";
                v[1] = "driver={SQL Server};server=sgpsql03.sgp.hp.com,2048;database=SPC_LOG;uid=logger;pwd=logger";
                v[2] = "Driver={Microsoft ODBC for Oracle};Server=FAB_DBS;Uid=fac_spc1;Pwd=12qwaszx;";
                v[3] = "server=.;database=TestData;uid=test;pwd=test";
    
                foreach (var item in v)
                {
                    bool isOdbc = false;
                    bool installed = false;
                    string driver = GetODBCDriverString(item);
                    if (!string.IsNullOrEmpty(driver))
                    {
                        isOdbc = true;
                        if (drivers.Contains(driver))
                        {
                            installed = true;
                        }
                    }
                    else
                    {
                        isOdbc = false;
                    }
                    if (isOdbc)
                    {
                        Console.WriteLine("For String: " + item + Environment
                            .NewLine + "Is Ocbc: true, driver: " + driver + " , is installed: " + installed + Environment.NewLine);
                    }
                    else
                    {
                        Console.WriteLine("For String: " + item + Environment
                            .NewLine + "Is Ocbc: false" + Environment.NewLine);
                    }
                }
    
    
                Console.ReadLine();
            }
    
            public static List<String> GetSystemDriverList()
            {
                List<string> names = new List<string>();
                // get system dsn's
                Microsoft.Win32.RegistryKey reg = (Microsoft.Win32.Registry.LocalMachine).OpenSubKey("Software");
                if (reg != null)
                {
                    reg = reg.OpenSubKey("ODBC");
                    if (reg != null)
                    {
                        reg = reg.OpenSubKey("ODBCINST.INI");
                        if (reg != null)
                        {
    
                            reg = reg.OpenSubKey("ODBC Drivers");
                            if (reg != null)
                            {
                                // Get all DSN entries defined in DSN_LOC_IN_REGISTRY.
                                foreach (string sName in reg.GetValueNames())
                                {
                                    names.Add(sName);
                                }
                            }
                            try
                            {
                                reg.Close();
                            }
                            catch { /* ignore this exception if we couldn't close */ }
                        }
                    }
                }
    
                return names;
            }
    
            public static string GetODBCDriverString(string connectionStr)
            {
                var match = Regex.Match(connectionStr, @"(?<={).+(?=})");
                if (match != null && !string.IsNullOrEmpty(match.Value))
                {
                    return match.Value;
                }
                return "";
            }
        }
    
    }
    

      

  • 相关阅读:
    关于excel导入、导出(POI)
    关于上传图片和显示
    关于sql连接查询(内联、左联、右联、全联)
    关于面试问题
    关于excel导出
    响应式布局和自适应布局的不同
    关于时间范围查询
    HDU 6166 Senior Pan(二进制分组+最短路)
    HUAS 2017暑假第六周比赛-题解
    AtCoder Regular Contest 081
  • 原文地址:https://www.cnblogs.com/netact/p/3499495.html
Copyright © 2020-2023  润新知