Generate a DLL package ASP code with VB to connect to the database.

xiaoxiao2021-03-06  63

This article connects the database (as an example of Access database) based on the DLL package ASP code generated by VB.

Under normal circumstances, we will usually perform the following operations when using the ASP to connect Access.

'//Proconn.asp< = server.createObject ("adoDb.connection" proconn.open "driver = {Microsoft Access Driver (* .mdb)}; uid =; pwd = 123; dbq =" Server.mappath ("db.asp") 'An Accss database for DB.mdb Change the suffix of DB.ASP, database password 123

If err.Number <> 0 Then Response.write "database is not connected, check" Response.endelse response.write "database link success" response.end end if%> <% Dim Proconnset Proconn = Server.createObject ("AdoDB. ")") Proconn.open "driver = {Microsoft Access Driver (* .mdb)}; uid =; pwd = 123; dbq =" & server.mappath ("db.asp") 'an original DB.mdb access Database Changes to DB.ASP files, database password 123

If Err.Number <> 0 THEN ??? response.write "database has no connection, please check" ??? response.endelse ??? response.write "database link success" ??? response.end end if?%>

If you configure the server, access Proconn.asp, if the connection database successfully outputs "Database Connection Success". But such an ASP code is very low, if this ASP is seen, then there is another database file, others can easily open your database. So our task is coming, how do these key content packaged? First, it is necessary to determine the method and objects. After reading some of the information on the Internet, it is mainly used by VB to generate a DLL method. So, we also take this way well, (although I haven't used VB this East) method to determine, what Is it the object we need to package? Let's see "Driver = {Microsoft Access Driver (* .mdb)}; uid =; pwd = 123; dbq =" & Server.mappath ("db.asp") is the most critical code, this code package is in one It should be better in the DLL generated by VB. The reason why the entire Dim ProconnSet Proconn = Server.CreateObject ("AdoDb.Connection") proconn.open "driver = {Microsoft Access Driver (* .mdb)}; uid =; pwd = 123; dbq =" & Server.mappath ("Db.asp") is packaged (because the online connection code is packaged) is because, when other ASP files reference proconn.asp, I also need other operations, if packaging, inconvenience Quote and operation. (The reason for the above package object is my personal opinion, there is no more affected by friends, this is not understood, this I don't understand, please tell me), I only want to package the most critical part of "" Driver = {Microsoft Access Driver (* .mdb)}; UID =; PWD = 123; DBQ = "& Server.mAppath (" DB.ASP ")" Analysis of this section to encapsulate, its first half is a string : "Driver = {Microsoft Access Driver (* .mdb)}; UID =; PWD = 123; DBQ =" Take another string of the back half of the back half. Another string of the second half is the return value of the server.mappath object function. This package begins this package. First create a new ActiveX DLL project, the project's name Project1 changed to the CONDBDLL ?? Method Class1 Change to the CS engineering name and method celebration When calling this DLL, you can define it according to your name rules, but please Be careful to use it.

The DLL code portion written as follows: Dim rp As ResponseDim rq As RequestDim ap As ApplicationDim sr As ServerDim sn As Session Public Sub OnStartPage (MyScriptingContext As ScriptingContext) Set rp = MyScriptingContext.ResponseSet rq = MyScriptingContext.RequestSet sr = MyScriptingContext.ServerSet ap = MyScriptingContext.ApplicationSet sn = MyScriptingContext.SessionEnd Sub Public Sub OnEndPage () Set rp = NothingSet rq = NothingSet sr = NothingSet ap = NothingSet sn = NothingEnd Sub 'the above statement is required, the original target has been simplified processing, and two The basic function is treated by processing public function connectdb () as variant connectdb = "driver = {microsoft access driver (* .mdb)}; uid =; pwd = 123; DBQ =" end function 'above this function is the first half of the processing The content of the string, directly returning this string 'additionally defines the following functions to process the second half of the content public function dbpath () as variant dbpath = sr.mappath ("db.asp") End function' Note that the above is SR, don't use a server to a key step, add the "Project library" of "Microsoft Active Server Pages ObjectContext Object Library", select "Project" in the menu -> "Reference", select in the open dialog box .

转载请注明原文地址:https://www.9cbs.com/read-119233.html

New Post(0)