9CBS - expert clinic -
Master: How to encapsulate database connections to DLL? And call? Emergency and other author: Bignobig () Credit value: 100 Forum: Web development ASP problem points: 100 Reply times: 24 Published: 2005-1-11 13:36:26 How to encapsulate database connections to DLL? And call? Anxiety
Reply to: bignobig () () Reputation: 100 2005-1-11 13:49:17 Score: 0 top!
TOP
Reply to: tatty_bad (I always appear where there is a place) () reputation: 100 2005-1-11 13:51:14 Score: 2 After the package goes, it is also modified? Ha ha.
So I recommend using a cache. . . This is better to implement the modified username password.
TOP
Reply to: Laihongbo524 (Ring Night Walks) () Reputation: 96 2005-1-11 13:57:41 Score: 60 Option Explicit
'VB ActiveX DLL module code
'
'----- Reference Some settings in ASP ------
Private ScriptingContext as asptypelibrary.scriptingContext
Private Server As AsPTypelibrary.server
'The following two subprograms are necessary
Public Sub onstartPage (PassedscriptingContext as scriptingcontext)
Set scriptingContext = PassedScriptingContext
SET Server = ScriptingContext.Server
End Sub
Public Sub OneendPage ()
'Cancel all references
Set scriptingContext = Nothing
SET Server = Nothing
End Sub
'If you use SQL database, you can, otherwise you want to reference asp.dll Microsoft Active Server Pages Object Library
'To quote Microsoft ActiveX Data Objects 2.8 Library
Public function conns () as adodb.connection
DIM Con As Adodb.Connection
Set con = new adodb.connection
'Access
Con -.open "provider = microsoft.jet.Oledb.4.0; data source =" & server.mappath ("# webdb.mdb")
'SQL
'Con.open "provider = sqloledb; user ID = sa; password = 123456; Initial Catalog = BBS; Data Source = 192.168.0.100;"
SET CONNS = Con
Set con = Nothing
END FUNCTION
Writing method in conn.asp of 'ASP
DIM CONN, CON
Set conn = server.createObject ("adoDb.connection")
Set con = Server.createObject ("Engineer Name. Class Module Name") SET CONN = Con.Conns
In 'ASP, you can use these operations like RS.Open "Select * from [Table], CONN, 1, 1, Conn.excute (" SELECT * from "")
TOP
Reply to: laihongbo524 (Ring Night Walk) () Reputation: 96 2005-1-11 14:00:55 Score: 0 If required to be modified
The code in the VB is as follows
Public Function Conns (Byval Dbfile As String) as adoDb.connection
DIM Con As Adodb.Connection
Set con = new adodb.connection
'Access
Con -.open "provider = microsoft.jet.Oledb.4.0; data source =" & dbfile
SET CONNS = Con
Set con = Nothing
END FUNCTION
Writing method in conn.asp of 'ASP
DIM CONN, CON
Set conn = server.createObject ("adoDb.connection")
Set con = Server.createObject ("Engineering Name. Class Module Name")
Set conn = con.conns (Server.MAppath ("DBNAME.MDB"))
TOP
Reply to: Mackyliu (NB League - Wild Talented Siles) () Reputation: 100 2005-1-11 14:09:14 Score: 2 As little as you do, brothers. I am afraid that people download the database has a solution, there is no need to use the component.
TOP
Reply to: qizu (竹) () Reputation: 100 2005-1-11 14:11:42 Score: 10 Component Engineering
Set up components
Engineering Name: Condbdll
Class module: CS
DIM RP As Response
DIM RQ As Request
DIM AP as Application
DIM SR AS Server
DIM SN AS Session
Public Sub onstartPage (MyScriptingContext as scriptingcontext)
Set rp = myscriptingContext.Response
SET RQ = myscriptingContext.request
SET SR = myscriptingContext.server
SET AP = myscriptingContext.Application
SET SN = myscriptingContext.Session
End Sub
Public Sub OneendPage ()
Set rp = Nothing
SET RQ = Nothing
SET SR = Nothing
SET AP = Nothing
SET SN = Nothing
End Sub
'The above statement is necessary, and the original object is simplified, and it works in two basic functions.
Public function connectdb () AS VARIANT
Connectdb = "driver = {SQL Server}; server = (local); database = database name; UID = username; pwd = password" End Function
2. Connection information
DIM Conn
DIM CONDL
DIM ConnStr
SET CONDL = Server.createObject ("condbdll.cs")
'CONDB is the created DLL object
Connstr = condl.connectdb ()
'Connecting two parts content composition string
ON Error ResMe next
Set conn = server.createObject ("adoDb.connection")
Conn.open connStr
IF Err THEN
Err.clear
Set conn = Nothing
Response.write "Database connection failed!" 'Comment, you need to translate these words into English.
Response.end
END IF
TOP
Reply to: fronm (time) () Reputation: 100 2005-1-11 14:12:30 Score: 2 Up
TOP
Reply to: hoggio_1980 (Nanlin Blossom) () Reputation: 100 2005-1-11 14:16:40 Score: 2 Follow!
TOP
Reply to: zhzhuo (programming mixed food) () reputation: 100 2005-1-11 14:48:41 Score: 2 Up
TOP
Reply to: Bignobig () () Reputation: 100 2005-1-11 15:01:48 Score: 0 Qizu (竹) I have seen it, but "user-defined types undefined" when generating DLLs, can not be generated?
TOP
Reply to: bignobig () () Reputation: 100 2005-1-11 15:04:17 Score: 0 LAIHONGBO524 (Rainbell Night Walk) The same, I pasted directly, "user-defined type undefined"
TOP
Reply to: laihongbo524 (windbell night thinking) () reputation: 96 2005-1-11 15:05:44 Score: 0 floor, this way, simple point
Public Function Connectdb () AS String
ConnectDB = "driver = {SQL Server}; server = (local); database = database name; UID = username; PWD = password"
END FUNCTION
2. Connection information
DIM Conn
DIM CONDL
'Connecting two parts content composition string
ON Error ResMe next
Set conn = server.createObject ("adoDb.connection")
SET CONDL = Server.createObject ("condbdll.cs")
Conn.open condl.connectdb ()
IF Err THEN
Err.clear
Set conn = Nothing
Response.write "Database connection failed!" 'Comment, you need to translate these words into English.
Response.end
END IF
TOP
Reply to: bignobig () () Reputation: 100 2005-1-11 15:11:53 Score: 0 Generate 3 files ".exp, .lib" these two useful? TOP
Reply to: NEWROCKY (Rocal) () Reputation: 90 2005-1-11 15:15:06 Score: 10 to Laihongbo524 (windbell night thinking)
What is your use? ? ?
Still not the same, take the connection series?
The main building is to encapsulate the connecting string in the DLL!
In fact, just return the Connection object!
'VB section
'The project here needs to reference Adodb
Public function connectdb () as adodb.connection
DIM CONN As New Adodb.connection
StrConnect = "driver = {sql server}; server = (local); database = database name; UID = username; PWD = password"
Conn.open strconnect
Set connectdb = conn
END FUNCTION
'ASP section
DIM Conn
DIM CONDL
'Connecting two parts content composition string
ON Error ResMe next
Set conn = server.createObject ("adoDb.connection")
SET CONDL = Server.createObject ("condbdll.cs")
SET CONN = CONDL.CONNECTDB ()
IF Err THEN
Err.clear
Set conn = Nothing
Response.write "Database connection failed!" 'Comment, you need to translate these words into English.
Response.end
END IF
TOP
Reply to: newhandtoo (stay card) () Reputation: 96 2005-1-11 15:15:27 Score: 2 to DLL, it will be
TOP
Reply to: bignobig () () Reputation: 100 2005-1-11 15:38:09 Score: 0 I use the Access database, the connection failed, registered the component, restarting the machine, but the connection failed!
Public function connectdb () AS VARIANT
ConnectDB = "DBQ =" & Server.mappath ("abc.mdb") & "; driver = {microsoft access driver (* .mdb)}; uid =; pwd = ABC"
END FUNCTION
DIM Conn
DIM CONDL
ON Error ResMe next
Set conn = server.createObject ("adoDb.connection")
SET CONDL = Server.createObject ("condbdll.cs")
Conn.open condl.connectdb ()
IF Err THEN
Err.clear
Set conn = Nothing
Response.write "ERR"
Response.end
END IF
TOP
Reply to: MyMyal123 (Feng Sen) () Reputation: 100 2005-1-11 15:38:19 Score: 2 Learning Top
Reply to: bignobig () () Reputation: 100 2005-1-11 15:43:57 Score: 0 NewRocky's appearance "User-defined type undefined"
TOP
Reply to: tfhui928 () Reputation: 95 2005-1-11 16:01:18 Score: 2 Follow
TOP
Reply to: bignobig () () Reputation: 100 2005-1-11 16:01:46 Score: 0 This is the error code:
Server object error 'ASP 0177: 800401F3'
Server.createObject failed
/index1.asp, line 12
Invalid PROGID.
TOP
Reply to: CNCCA (Coke) () Reputation: 100 2005-1-11 16:04:20 Score: 2 Components Unregistered ???
TOP
Reply to: mymyal123 (Feng Sen) () Reputation: 100 2005-1-11 16:07:32 Score: 2 Database connection failed
TOP
Reply to: bignobig () () Reputation: 100 2005-1-11 16:09:28 Score: 0 Register
TOP
Reply to: bignobig () () Reputation: 100 2005-1-11 16:48:49 Score: 0 laihongbo524 (wind ball night thinking)
alright, alright! ! !
Everyone is connected! ! !
TOP
This problem has been posted, score record: Tatty_Bad (2), Laihongbo524 (60), Mackyliu (2), Qizu (10), FRONM (2), hoggio_1980 (2), zhzhuo (2), newrocky (10), Newhandtoo (2), MyMyal123 (2), TFHUI928 (2), CNCCA (2), MymyAl123 (2),