ado连接数据库模块
2024-07-21 02:23:17
供稿:网友
加入这个模块后,在程序中任意地方调用:
打开ado数据库连接:call cnndb(mcnn, scnn, true)
关闭ado数据库连接:call discnn(mcnn)
这样,让数据库连接更加方便被连接和关闭
'%#******************************************
'%#*窗体名称:mdldb
'%#*功能描述:加入这个模块后调用 call cnndb(gcnndb, scnn, true)
'%#*作者: 宁彦彬
'%#*修改日期:2002-12-03
'%#******************************************
'%#*option explicit
public sub cnndb(byref mcnn as adodb.connection, scnn as string, optional blnclient as boolean)
'*purpose: connect local sqlserver
'*note: 在这里数据连接
on error goto myerr
if blnclient = true then
mcnn.cursorlocation = aduseclient
else
mcnn.cursorlocation = aduseserver
end if
mcnn.connectionstring = scnn '定义好的
mcnn.open
myexit:
exit sub
myerr:
msgbox "服务器没有运行" & vbcrlf & err.number & vbcrlf & err.description, vbcritical, "错误"
goto myexit
end sub
public sub discnn(byref mcnn as adodb.connection)
'*purpose: disconnect local sqlserver
'*note: 在这里数据断开连接
on error goto myerr
mcnn.close
set mcnn = nothing
myexit:
exit sub
myerr:
goto myexit
end sub
function serverdate(byref mcnn as adodb.connection)
'*purpose: 取到服务器的系统时间
'*note: 必须在mcnn初始化后再用
' msgbox serverdate(mcnn)
on error goto myerr
dim rst as new adodb.recordset
set rst = mcnn.execute("select getdate()")
serverdate = rst(0)
rst.close
set rst = nothing
myexit:
exit function
myerr:
goto myexit
end function