將連線資料庫的程式碼隱藏在DLL中(轉)

RegisterForBlog發表於2007-09-19
將連線資料庫的程式碼隱藏在DLL中(轉)[@more@]

  其實,大家在書寫asp程式時,最擔心的可能就是資料庫的連線資訊,會被一些人看到,進行一些破壞。下面我們用vb6.0來做一個動態連結庫(.dll)來隱藏資料庫的連線資訊。

  啟動vb6.0,新建--&gtActive dll工程。單擊"工程"--&gt引用,選擇"microsoft active server pages object library"

  和"microsoft activeX data objects 2.1 library"兩項。將類模組的名稱改為dcss.將工程的名稱改為yygwy.儲存工程檔案yygwy.vbp和類檔案dcss.cls。

  在dcss.cls中寫入:

  Private myscriptingcontext As ScriptingContext

  Private myapplication As Application

  Private myrequest As Request

  Private myresponse As Response

  Private myserver As Server

  Private mysession As Session

  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 rsresult(strsql As String) As Recordset

  Dim mycnn As Connection

  Dim myset As Recordset

  Dim strconnstring As String

  'strconnstring = "provider=sqloledb.1;

  password=;" & "user id=sa;" & "initial catalog=vlog;" & "data source=hpe60;

  connect timeout=15"

  strconnstring = "driver={sql server};server=yang;uid=sa;pwd=;

  database=dcss"

  'mycnn.ConnectionString = strconnstring

  mycnn.Open strconnstring

  myset.ActiveConnection = mycnn

  myset.Open strsql, mycnn, 3, adCmdText

  Set rsresult = myset

  End Function

  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")

  

·上一篇:

·下一篇:
 
     最新更新
·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·

·


| | | | | | |

Copyright © 2004 - 2007 All Rights Reserved

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10763080/viewspace-970194/,如需轉載,請註明出處,否則將追究法律責任。

將連線資料庫的程式碼隱藏在DLL中(轉)
請登入後發表評論 登入
全部評論

相關文章