Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLL Database Connections - more help

Status
Not open for further replies.

PeterMac

Programmer
Mar 9, 2001
51
CA
Hi:

I am trying to get a DLL to connect to a database and return a TRUE/FALSE based on results...

Can anyone point me to a link SPECIFICALLY on this topic. Or help me with this code... All me reading says it should work, but I think I am missing a part on how to register the DLL. I am using IIS on Win2000 Server and I am developing the DLL on the same machine... so I am told that the DLL should already be registered on my system.

I have the following code that I wrote myself, and am getting an "Object Required" error when I call the function in my ASP...

=================================
DLL VB Code
=================================

Public Function login_test(user_id, password) As Boolean
Dim objConn, strConnection, objRS, strQuery, Answer

Set objConn = Server.CreateObject("ADODB.Connection")
strConnection = "DSN=secure;Database=secure;UID=secure_login;PWD=simonp;"
objConn.Open strConnection

strQuery = "SELECT * FROM login WHERE userid = '" & user_id & "';"
Set objRS = objConn.Execute(strQuery)

If objRS.EOF = True Then
Answer = False
Else
If objRS(&quot;password&quot;) <> password Then
Answer = False
Else
Answer = True
End If
End If

login_test = Answer

End Function

=================================
ASP Code
=================================
<% @LANGUAGE = VBScript %>
<% option explicit

Response.Expires = 0

Dim objConn, objRS, strQuery, loginOBJ, result
Dim strConnection, strBuild, form_psw, database_psw, form_user, database_user

If Request.ServerVariables(&quot;CONTENT_LENGTH&quot;) <> 0 Then

form_user = request.form(&quot;username&quot;)
form_psw = request.form(&quot;password&quot;)

'register the DLL object and instantiate it as loginOBJ
set loginOBJ = server.createobject(&quot;GPN.login&quot;)

result = loginOBJ.login_test(form_user, form_psw)

if result = FALSE then
Response.Cookies(&quot;UserName&quot;) = &quot;&quot;
response.redirect &quot;messages/login_failed.asp&quot;
else
Response.Cookies(&quot;UserName&quot;) = form_user
response.redirect &quot;index.asp&quot;
end if

end if

%>
 
Have you compiled the dll? Usually when you compile the dll it automatically registers but then again you never know.
You can also run the dll in the background with vb and then launch your web page. This can prove very useful when troubleshooting.
Other than that you can always run regsvr32 to make sure your dll is registered.
 
I'm not an expert on DLL's, but have you imported in the server object? Also, you need to initialize a server object somewhere so that you can reference later...

eg:

Dim gServer as Server
.
.
.

Set objConn = gServer.CreateObject(&quot;ADODB.Connection&quot;)

something like this should work.

A better way to do it (I think) would be to import in the the ADO objects, and create a connection that way.

eg:
in your fxn:

Dim objConn as ADODB.Connection
objConn.open strConnection

hth
leo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top