1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /// <summary> /// 读取注册表,根据Office版本获取数据库连接字段 /// </summary> /// 数据库连接字段 private string GetConnectionString() { string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " ; RegistryKey rk = Registry.LocalMachine; //查询Office2003 RegistryKey f03 = rk.OpenSubKey( @"SOFTWAREMicrosoftOffice11.0AccessInstallRoot" ); //查询Office2007 RegistryKey f07 = rk.OpenSubKey( @"SOFTWAREMicrosoftOffice12.0AccessInstallRoot" ); //查询Office2010 RegistryKey f10 = rk.OpenSubKey( @"SOFTWAREMicrosoftOffice14.0AccessInstallRoot" ); if (f03 != null ) { strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " ; } else if (f07 != null || f10 != null ) { strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " ; } return strConnectionString; } |
读取注册表根据Office版本获取数据库连接字段
本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/database/access/5333.html