get all ODBC drivers 驱动
2013-12-31 15:15
246 查看
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 ""; } } }
相关文章推荐
- SQLGetInstalledDrivers 获取ODBC已经安装的驱动列表
- 【VC++】SQLGetInstalledDrivers 获取系统驱动。
- About MS Sql 2000,to get all triggers or foreign key constraints.
- 安装mysql connector odbc 后在 控制面板 数据源下没有找到mysql的驱动
- document.all与getElementById、getElementsByName、getElementsByTagName用法区别-getElementById
- PDF抽词报错:java.lang.NullPointerException at org.pdfbox.pdmodel.PDPageNode.getAllKids(PDPageNode.java:194)
- linux 下的串口驱动和《Linux Device Drivers》学习感受
- Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005'
- 在64位的系统上使用32为的ODBC驱动
- (COPY)document.all和document.getElementById用法 document.all用法:
- Access_error:Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005'
- linux内核外部驱动模块编译报错ERROR—drivers/*.ko] undefined
- Fedora13下为postgresql添加ODBC驱动过程
- linux内核外部驱动模块编译报错ERROR: "******" [drivers/**.ko] undefined!
- iredmail下安装脚本分析(一)---get_all.sh 文件所在目录为PKGS
- iredmail下安装脚本分析(一)---get_all.sh 文件所在目录为PKGS
- php getallheaders无法获取自定义头的问题
- 关于连接mysql数据库——安装ODBC驱动报错
- odbc 驱动 windows10 安装
- javascript:document.all & document.getElementsByName