參考資料:https://www.cnblogs.com/liuzhaoyzz/p/6406629.html
今天用VBS讀寫MDB數據庫,把原來在asp裏面運行正常的代碼拿過來,發現總是出現 x800a0e7a 錯誤:
查了一下,纔想起來是因爲64位系統未啓用 32 位 MDB 數據庫引擎造成的。
纔回想起來當初 IIS7.5 裏面跑 asp 的時候也出現過這個問題,改了下 IIS 設置允許32位程序倒是解決了。
但是 VBS 和 ASP 有點點不同,無法象 IIS 那樣有個設置,怎麼辦呢?
又查了下,發現有網友解決過類似的問題:64位系統VBS調用32位COM組件(https://www.cnblogs.com/liuzhaoyzz/p/6406629.html),看起來是在使用 CreateObject 之前根據系統類型處理了一下 VBS 運行環境的設置,於是拿過來一用,發現也適用於 MDB 數據庫引擎的創建,連接 MDB 數據庫運行成功!
Option Explicit
call Run32()
dim conn,rs,rsB,connStr,sql,DBName
dim url1
dim apppath
apppath=left(wscript.scriptfullname,instrrev(wscript.scriptfullname,"\")-1)
Set conn = CreateObject("ADODB.Connection")
SET Rs = CreateObject("ADODB.Recordset")
DBName=apppath & "\t1.mdb"
connStr = "Provider = Microsoft.Jet.OLEDB.4.0;data source = " & DBName & ";Persist Security Info=False"
conn.Open connstr
sql="Select * from zytq Where id=1"
Set Rs=conn.Execute(sql)
url1=Rs("url")
call CloseDB(1)
msgbox url1
Public Sub CloseDB(allClose)
'1 ,AllClose & Nothing
'0 ,AllClose
'2 ,RS Close
'3 ,RS Close & Nothing
On Error Resume Next
If allClose = 1 Then
If Not RS Is Nothing Then
If RS.State = 1 Then RS.Close
Set RS = Nothing '----------------
End If
If Not conn Is Nothing Then
If conn.State = 1 Then conn.Close
Set conn = Nothing '---------------------
End If
ElseIf allClose = 0 Then
If Not RS Is Nothing Then
If RS.State = 1 Then RS.Close
End If
If Not conn Is Nothing Then
If conn.State = 1 Then conn.Close
End If
ElseIf allClose = 2 Then
If Not RS Is Nothing Then
If RS.State = 1 Then RS.Close
End If
ElseIf allClose = 3 Then
If Not RS Is Nothing Then
If RS.State = 1 Then RS.Close
Set RS = Nothing '--------------
End If
End If
'Response.write "function1 CONN closeed!"
End Sub
爲表謝意,Run32() 子程序我就不在這裏貼出來了,需要的網友請前往 https://www.cnblogs.com/liuzhaoyzz/p/6406629.html 自行查看。
在此謝過!