如何检查系统上是否安装了OLEDB驱动程序?

发布于 2024-07-05 00:08:01 字数 151 浏览 10 评论 0原文

如何确保在启动应用程序时安装了特定的 OLEDB 驱动程序? 我使用 Delphi 中的 ADO,并且希望在缺少驱动程序时显示描述性错误消息。 从 ADO 返回的错误并不总是那么用户友好。

可能有一个不错的小函数可以返回所有已安装的驱动程序,但我还没有找到它。

How can I make sure that a certain OLEDB driver is installed when I start my application? I use ADO from Delphi and would like to display a descriptive error message if the driver is missing. The error that's returned from ADO isn't always that user-friendly.

There are probably a nice little function that returns all installed drivers but I haven't found it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

‘画卷フ 2024-07-12 00:08:02
namespace Common {
  public class CLSIDHelper {

  [DllImport("ole32.dll")]
  static extern int CLSIDFromProgID([MarshalAs(UnmanagedType.LPWStr)] string lpszProgID, out Guid pclsid);


  public static Guid RetrieveGUID(string Provider) {
    Guid CLSID = Guid.Empty;
    int Ok = CLSIDFromProgID(Provider, out CLSID);
    if (Ok == 0)
       return CLSID;
    return null;
  }
 }
}
namespace Common {
  public class CLSIDHelper {

  [DllImport("ole32.dll")]
  static extern int CLSIDFromProgID([MarshalAs(UnmanagedType.LPWStr)] string lpszProgID, out Guid pclsid);


  public static Guid RetrieveGUID(string Provider) {
    Guid CLSID = Guid.Empty;
    int Ok = CLSIDFromProgID(Provider, out CLSID);
    if (Ok == 0)
       return CLSID;
    return null;
  }
 }
}
若言繁花未落 2024-07-12 00:08:02

您可以获取 ADO 提供程序名称并在注册表中的路径 HKEY_CLASSES_ROOT\[Provider_Name] 中检查它。

You can get a ADO provider name and check it in registry at path HKEY_CLASSES_ROOT\[Provider_Name].

°如果伤别离去 2024-07-12 00:08:02

最简单的方法难道不是在启动时尝试建立连接并捕获错误吗?

我的意思是,您可能会收到一些不同的错误,例如,取决于用户是否在线,但您应该能够测试这些情况。

Wouldn't the easiest way just be trying to make a connection at start-up and catching the error?

I mean you might get a few different errors back depending on, for example, the user is online, but they're cases that you should be able to test for.

两仪 2024-07-12 00:08:02

我相信有问题的 OLEDB 对象埋藏在注册表中的某个位置,因为 OLEDB / ADO 是 COM 解决方案。 我的猜测是看看您是否可以在注册表中找到安装驱动程序的 GUID。

I believe the OLEDB objects in question are buried someplace in the registry, since OLEDB / ADO is a COM solution. My guess would be to see if you can find the GUID that your driver is installed as in the registry.

舂唻埖巳落 2024-07-12 00:08:01

每个提供程序都有一个与其类关联的 GUID。 要查找 GUID,请打开 regedit 并在注册表中搜索提供程序名称。 例如,搜索“Microsoft Jet 4.0 OLE DB 提供程序”。 找到它后,复制该密钥(GUID 值)并在应用程序的注册表搜索中使用它。

function OleDBExists : boolean;
var
  reg : TRegistry;
begin
  Result := false;

  // See if Advantage OLE DB Provider is on this PC
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_LOCAL_MACHINE;
    Result := reg.OpenKeyReadOnly( '\SOFTWARE\Classes\CLSID\{C1637B2F-CA37-11D2-AE5C-00609791DC73}' );
  finally
    reg.Free;
  end;
end;

Each provider has a GUID associated with its class. To find the guid, open regedit and search the registry for the provider name. For example, search for "Microsoft Jet 4.0 OLE DB Provider". When you find it, copy the key (the GUID value) and use that in a registry search in your application.

function OleDBExists : boolean;
var
  reg : TRegistry;
begin
  Result := false;

  // See if Advantage OLE DB Provider is on this PC
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_LOCAL_MACHINE;
    Result := reg.OpenKeyReadOnly( '\SOFTWARE\Classes\CLSID\{C1637B2F-CA37-11D2-AE5C-00609791DC73}' );
  finally
    reg.Free;
  end;
end;
乙白 2024-07-12 00:08:01

这是一个老问题,但我现在遇到了同样的问题,也许这可以帮助其他人。

在 Delphi 7 中,ADODB 中有一个过程返回带有提供程序名称的 TStringList。

使用示例:

names := TStringList.Create;
ADODB.GetProviderNames(names);

if names.IndexOf('SQLNCLI10')<>-1 then
  st := 'Provider=SQLNCLI10;'
else if names.IndexOf('SQLNCLI')<>-1 then
  st := 'Provider=SQLNCLI;'
else if names.IndexOf('SQLOLEDB')<>-1 then
  st := 'Provider=SQLOLEDB;';

This is an old question but I had the same problem now and maybe this can help others.

In Delphi 7 there is an procedure in ADODB that return a TStringList with the provider names.

Usage example:

names := TStringList.Create;
ADODB.GetProviderNames(names);

if names.IndexOf('SQLNCLI10')<>-1 then
  st := 'Provider=SQLNCLI10;'
else if names.IndexOf('SQLNCLI')<>-1 then
  st := 'Provider=SQLNCLI;'
else if names.IndexOf('SQLOLEDB')<>-1 then
  st := 'Provider=SQLOLEDB;';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文