win7 win10 x64系统下的 vbs 连接 mdb 数据库方法

本文介绍了在64位系统中使用VBS读写32位MDB数据库时遇到的x800a0e7a错误,并提供了详细的解决方案。通过调整VBS运行环境的设置,使32位MDB数据库引擎能够在64位系统上正常工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考资料: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 自行查看。

在此谢过!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jessezappy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值