如何以编程方式测试Mysql ODBC驱动程序的版本

时间:2016-12-07 09:31:52

标签: mysql vbscript odbc

我使用asp(vbscript)连接到mysql,但我不知道ODBC驱动程序的版本。我无法访问服务器管理和Windows注册表,所以:

1-我想以编程方式找到ODBC的版本(或者可能通过phpmyadmin中的sql命令?)。

2-但是作为一种可能的解决方案,我认为循环遍历各种连接字符串可能会有所帮助。如何传递错误并找到合适的连接字符串?连接字符串是否有回调或False / True返回?

可能的连接字符串:

    set objcon = Server.CreateObject ("ADODB.Connection")    
    objcon.connectionstring = "Driver={MySQL ODBC 5.2 UNICODE Driver};Server=****;Database=****;User=****;Password=****;Option=3;"
    objcon.connectionstring = "Driver={MySQL ODBC 5.1 Driver};Server=****;Database=****;User=****;Password=****;Option=3;"
    objcon.connectionstring = "Driver={MySQL ODBC 3.51 Driver};Server=****;Database=2558_academy;User=****;Password=****;Option=3;"

3 个答案:

答案 0 :(得分:1)

set filepath=%~f1
set  file=%filepath:\=\\%
wmic datafile where name^="%file%" get version|findstr /i /v /c:"version"
echo %errorlevel%

使用WMI的批处理文件,任何COM语言都可以使用。将驱动程序文件作为参数传递给批处理文件。

答案 1 :(得分:1)

如果你想在没有安装驱动程序的情况下连接到MySQL数据库,你应该遍历一个可能的连接字符串列表并尝试它们直到第一个成功。

打开连接后,您可以解析连接字符串或使用连接的合适属性。

在代码中:

   Dim oCnct : Set oCnct = CreateObject("ADODB.Connection")
  Dim sDrv
  For Each sDrv In Split("Complete nonsense|MySQL ODBC 5.1 Driver|MySQL ODBC 9.9 Driver", "|")
      WScript.Echo sDrv
     On Error Resume Next
      oCnct.Open Replace("Driver={§};Server=gent;Database=pi;User=pa;Password=po;Option=3;", "§", sDrv)
      If 0 = Err.Number Then
         Exit For
      Else
         WScript.Echo "Error:", Err.Description
      End If
     On Error Goto 0
  Next
  If oCnct.State = adStateOpen Then
     WScript.Echo "Connected to MySQL using", sDrv
     Dim sProp
     For Each sProp In Split("Driver Version|Driver ODBC Version", "|")
         WScript.Echo oCnct.Properties(sProp).Name & ":", oCnct.Properties(sProp).Value
     Next
     oCnct.Close
  Else
     WScript.Echo "Failed to connected to MySQL"
  End If

输出:

Complete nonsense
Error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
MySQL ODBC 5.1 Driver
Connected to MySQL using MySQL ODBC 5.1 Driver
Driver Version: 05.01.0005
Driver ODBC Version: 03.51

答案 2 :(得分:0)

虽然您可能无法打开注册表,但您可以通过winmgmts服务进行查询。您可以根据自己的喜好进行修改...让我知道它是否有效。否则可能有

for each key in split("SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers,x86|SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\ODBC Drivers,x64", "|")
    strKeyPath=split(key, ",")(0)
    arch=split(key, ",")(1)
    Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
    objRegistry.EnumValues &H80000002, strKeyPath, arrValueNames, arrValueTypes
    For i = 0 to UBound(arrValueNames)
        strValueName = arrValueNames(i)
        objRegistry.GetStringValue &H80000002,strKeyPath,strValueName,strValue
        Wscript.Echo "[" & arch & "] "& strValue & " " & arrValueNames(i) 
    Next
Next

如果您在文件系统中提供了有关连接器本身的安装的更多信息,则可以更容易地以编程方式检测。

C:\Windows\System32\odbcad32.exe - GUI tool for seeing the drivers
cd /d "C:\Program Files"
dir /s /b *odbc*dll | find /I "MySQL"

找到MySQL的正确odbc dll后,通常可以从文件夹路径中readme.txt文件的顶行抓取驱动程序版本。

相关问题