Option ExplicitPrivate Context As ScriptingContext
Private Application As Application
Private Response As Response
Private Request As Request
Private Session As Session
Public conn As ADODB.Connection
Private rs As ADODB.Recordset
Private Server As Server
Private key As String
Public Sub OnStartPage(PassedscriptContext As ScriptingContext)
Set Context = PassedscriptContext
Set Application = Context.Application
Set Request = Context.Request
Set Response = Context.Response
Set Server = Context.Server
Set Session = Context.SessionEnd Sub
Private Sub Class_Initialize()     Set conn = DbConn()End Sub
Public Function setKey(key_)
   key = key_
End FunctionPublic Function getKey()
   getKey = key
End Function'==========================
'  connect to database
'==========================
Public Function DbConn()
   Dim connstr As String
   Dim conn1 As New ADODB.Connection
   Set conn1 = New ADODB.Connection
   connstr = "driver={sql server};database=biran;uid=sa;password=sa;server=(local);stmt=set names 'gbk'"
   conn1.Open connstr
   If Err <> 0 Then
      Err.Clear
   End If
   DbConn = conn1
End Function
Public Function getRecord()Set rs = New ADODB.Recordset
rs.Open "select * from aa", conn, 1, 1
If Not rs.EOF Then
   Do While Not rs.EOF
      Response.Write rs("name") & "<br>"
   rs.MoveNext
   Loop
 Else
   Response.Write "none"
 End If
 rs.Close
End Function
Public Sub OnEndPage()
Set Application = Nothing
Set Request = Nothing
Set Response = Nothing
Set Server = Nothing
Set Session = Nothing
Set Context = Nothing
End Sub
上面这段代码,我把它的工程名改为biran   类名改为tst然后用regsvr32 biran.dll注册成功。
再在ASP中写set c=server.createobject("biran.tst")
为什么这样写会出错?

解决方案 »

  1.   

    好像不需要加“server.”吧,另外iis好像需要设置下的,默认的不允许随便创建active对象的。
      

  2.   

    直接用createobject也是报错。
    IIS好像没有什么关系吧。。这个是系统注册过的。
      

  3.   

    dim c as New biran.tst
    试试
      

  4.   

    在VB中可以写成dim c as new biran.tst在ASP中不可以。。
      

  5.   

    那要看 asp 报什么错了
      

  6.   

    我再说明白一点吧。引用了Microsoft ActiveX Server Page Libery 和 Microsoft ActiveX Data 2.6
    然后在server.createObject  那一行报这个错:biran (0x800A01A8)
    需要对象