This article uses the DLL encapsulated ASP code generated by VB to connect to the database (taking the Access database as an example).
Generally speaking, when we use ASP to connect to Access databases, we usually perform the following operations.
'//Proconn.asp
<%
dimProConn
setProConn=Server.CreateObject("ADODB.CONNECTION")
ProConn.Open"driver={Microsoft AccessDriver(*.mdb)};uid=;pwd=123;DBQ="&Server.MapPath("DB.asp")
'A file with the suffix DB.asp that was originally DB.mdb changed to DB.asp, database password 123
iferr.Number<>0then
ResPonse.Write "The database has no connection, please check"
ResPonse.End
else
ResPonse.Write "Database Link Successfully"
ResPonse.End
endif
%>
If the server is configured, access Proconn.asp. If the database connection is successful, the output will be "Database connection successful".
However, the security level of such as asp code is very low. If this asp original is seen, then with this database file, others can easily
Open your database for operation.
So our task is here, how to encapsulate these key content?
First, we need to determine the methods and objects.
After checking some information on the Internet, they mainly use VB to generate DLLs to encapsulate them. So we should also adopt this method, (although I have not really used VB yet)
The method is determined, so what are the objects we need to encapsulate?
Come and see everyone
"driver={Microsoft AccessDriver(*.mdb)};uid=;pwd=123;DBQ="&Server.MapPath("DB.asp")
It is the most critical code. This code should be better encapsulated in a DLL generated with VB.
The reason why not put the whole
dimProConn
setProConn=Server.CreateObject("ADODB.CONNECTION")
ProConn.Open"driver={Microsoft AccessDriver(*.mdb)};uid=;pwd=123;DBQ="&Server.MapPath("DB.asp")
All are encapsulated (because it is said that the entire connection code is encapsulated) is because when other asp files refer to Proconn.asp,
I also need the ProConn inside to do other operations, and if encapsulated, it is inconvenient to reference and operate.
(The reason for the above explanation of the encapsulation object is my personal opinion. Some friends said that the overall encapsulation has no effect on the use of ProConn. I don’t understand this, please tell me if you know it)
I only want to encapsulate the most critical part ""driver={Microsoft AccessDriver(*.mdb)};uid=;pwd=123;DBQ="&Server.MapPath("DB.asp")"
Analyze the content to be encapsulated.
The first half of it is a string:
"driver={Microsoft AccessDriver(*.mdb)};uid=;pwd=123;DBQ="
Use & to connect another string in the second half.
Another string in the second half is the return value of the Server.MapPath object function.
The following is the operation process of this package.
first
Create a new ActiveXDLL project under VB, change the name of the project Project1 to ConDBDLL?? The name of the method class1 is changed to cs