使用组件封装ASP的数据库操作,使用组件封装ASP的数据库操作
【 tulaoshi.com - ASP 】
大家在书写asp程序时,最担心的可能就是数据库的连接信息,会被一些人看到,进行一些破坏。下面我们用vb6.0来做一个动态链接库(.dll)来隐藏数据库的连接信息。Public  Sub  onstartpage(passedscriptingcontext  As  ScriptingContext) 
Set  myscriptingcontext  =  passedscriptingcontext 
Set  myapplication  =  myscriptingcontext.Application 
Set  myrequest  =  myscriptingcontext.Request 
Set  myresponse  =  myscriptingcontext.Response 
Set  myserver  =  myscriptingcontext.Server 
Set  mysession  =  myscriptingcontext.Session 
End  Sub 
Public  Sub  onendpage() 
Set  myscriptingcontext  =  Nothing 
Set  myapplication  =  Nothing 
Set  myrequest  =  Nothing 
Set  myresponse  =  Nothing 
Set  myserver  =  Nothing 
Set  mysession  =  Nothing 
End  Sub 
'以上语句是必须的。 
'定义两个公有函数 
Public  Function  datasource()  As  Variant 
datasource  =  "driver={sql  server};server=yang;uid=sa;pwd=;  database=dcss" 
End  Function 
编译生成dcss.dll文件。注册regsvr32  路径dcss.dll。 
用visual  interdev打开global.asa文件.当然了,你也可以在其它文件中使用。 
set    dcss=server.CreateObject("yygwy.dcss")   
oconn=dcss.datasource()           
application("strconn")=oconn   
在其它的页面中如下调用即可: 
set  objConn  =  Server.CreateObject("ADODB.Connection") 
objConn.Open  application("strconn") 
来源:http://www.tulaoshi.com/n/20160129/1510471.html
看过《使用组件封装ASP的数据库操作》的人还看了以下文章 更多>>