因用户使用的数据库系统不同,程序可能使用Interbase\sql server\Oracle系统之一。程序中用ODBC数据源来连接数据库,怎么得到当前连接的数据库系统的名称和版本呢?读注册表的ODBC信息吗?

解决方案 »

  1.   

    先把 HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\数据源名\ 下的Driver项读出来,
    再用 GetFileVersionInfo获取Driver的名称和版本等信息。
      

  2.   

    这是我连接数据库的代码:
    var
      SQLFile, LogFile: TextFile;
      Error, SQLErr: Boolean;
      SQLFileName, strTmp: String;
      ComConnection: OleVariant;
    begin
      //设置日期格式
      DateSeparator := '/';
      TimeSeparator := ':';
      LongTimeFormat := 'yyyy-mm-dd';
      LongDateFormat := 'hh:nn:ss';
      //打开连接
      Error := False;  ComConnection := CreateOleObject('ADODB.Connection');
      ComConnection.ConnectionString := 'DSN=Ant2000;UID=Ant;PWD=tct1810';
    {
      ComConnection.Mode := 3;             // adModeReadWrite
      ComConnection.CursorLocation := 3;   // adUseClient
    }
    {
      连接字符串
      SQL Server 7
      Provider=MSDASQL.1;Password=tct1810;Persist Security Info=True;
      User ID=ant2000p;Data Source=Ant2000View  Interbase
      Provider=MSDASQL.1;Password=tct1810;Persist Security Info=True;
      User ID=ant;Data Source=Ant2000View;Connect Timeout=15;
      Extended Properties="DSN=Ant2000View;UID=ANT;PWD=tct1810;
      DB=E:\Work\Ant2000View\gdb\Ant2000.gdb";Locale Identifier=2052
    }
    //  if ADOConnMain.Connected then Exit;
      try
        ComConnection.Open;
      except
        Error := True;
      end;  while Error do
        if Application.MessageBox('错误:无法连接到数据库服务器'
          + #13#10'详细情况:数据库服务器没有启动或ODBC数据源没有设置或设置错误',
          PCHAR(Application.Title), MB_RETRYCANCEL or MB_ICONERROR)=IDRETRY then
          try
            ComConnection.ConnectionString := PromptDataSource(0,
              'Provider=MSDASQL.1;Password=tct1810;'
              + 'Persist Security Info=True;Data Source=Ant2000;');
            ComConnection.Open;
            Error := False;
          except
            Error := True;
          end
        else begin
          Tag := -1;
          Exit;
        end;  ADOConnMain.ConnectionObject := IUnknown(ComConnection) as _Connection;除了读注册表,还有没有其他方法?