首页 > 数据库 > Access > 正文

读取注册表根据Office版本获取数据库连接字段

2020-01-30 23:50:50
字体:
来源:转载
供稿:网友
/// <summary> /// 读取注册表,根据Office版本获取数据库连接字段 /// </summary> /// <returns>数据库连接字段</returns> private string GetConnectionString() {   string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = ";    RegistryKey rk = Registry.LocalMachine;   //查询Office2003   RegistryKey f03 = rk.OpenSubKey(@"SOFTWARE/Microsoft/Office/11.0/Access/InstallRoot/");   //查询Office2007   RegistryKey f07 = rk.OpenSubKey(@"SOFTWARE/Microsoft/Office/12.0/Access/InstallRoot/");   //查询Office2010   RegistryKey f10 = rk.OpenSubKey(@"SOFTWARE/Microsoft/Office/14.0/Access/InstallRoot/");    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; }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表