Wrox Programmer Forums
|
Classic ASP Components Discussions specific to components in ASP 3.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Components section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2003, 03:59 AM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Activex DLL components

Hi there

I have been looking into find some pages with tutorials/artikles on creating DLL components but have not been able to find any. Can someone give me some links to that or give me an example on how to create Dll's ?

/vbmo
 
Old June 5th, 2003, 08:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

try these for "absolute beginner" articlers on using VB to create the DLLs:
http://www.4guysfromrolla.com/webtech/040300-1.shtml
http://www.microsoft.com/mind/0999/vbcom/vbcom.asp
 
Old June 6th, 2003, 03:32 AM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thanks But if there should be some tutorials/artikles on using Sql in the dll i would like those to :o)

/vbmo
 
Old June 6th, 2003, 06:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

How about these SQL and ADO tutorials?
http://www.w3schools.com/sql/default.asp
http://www.w3schools.com/ado/default.asp

any decent search engine will find you loads like these on the web...
 
Old June 6th, 2003, 01:55 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi vbmo,

What exactly are you looking for? If I recall correctly, Microsoft has created a sample application using a VB DLL for a common Data Access Layer with methods like ExecuteSprocGetRecordSet, ExecuteSQLetc. I searched google for this, but couldn't find it anymore.

The company I work for has used this example to create our own DAL, so if you have any specific questions, feel free to ask.

Cheers,

Imar
 
Old June 6th, 2003, 04:45 PM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar

I am simply looking for some toturials/artikles on creating dll's using VB. But the part with the "Hello World" is not enough i want to learn how to include sql and ado in my dll's :o)

/vbmo
 
Old June 7th, 2003, 07:17 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi vbmo,

I am sure there are a couple of tutorials / faqs on the net describing how to create a VB DLL using ADO, but I couldn't find one in my bookmarks. However, it's not too difficult. Using ADO in VB is more or less the same as in ASP. The biggest thing to watch for is passing parameters in and out of procedures. The type (strongly typed versus a Variant) of the parameters is important.

You can read more about that here: http://support.microsoft.com:80/supp...NoWebContent=1

OK, now for the "mini tutorial"

1. Start a new ActiveX DLL project and add a reference to the Microsoft ActiveX Data Objects 2.5/2.6

2. Create a property (type string) to hold the connection string. Alternatively, add the connection string as a hard coded value, although this is not recommended.

3. Add a method (a Sub) like ExecSproc with the following code:

Code:
Public Sub ExecSproc(ByVal NameOfSproc As String)
    '===============================================================
    '   NAME: ExecSproc
    '   DATE CREATED: 
    '   CREATED BY: 
    '   CREATED FOR: 
    '   FUNCTION: Executes a sproc that does not return any records
    '   IN: NameOfSproc. The name of the sproc to execute
    '   OUT: Nothing
    '   RETURNS: Nothing
    '   VERSION: 1
    '   EXAMPLE:
    '===============================================================

    On Error GoTo errorHandler

    Dim connConnection As ADODB.Connection
    Dim cmdCommand As ADODB.Command

    Set connConnection = New ADODB.Connection
    Set cmdCommand = New ADODB.Command

    With connConnection
        .Open YourConnectionString
    End With

    With cmdCommand
        ' Set command properties
        .ActiveConnection = connConnection
        .CommandType = adCmdStoredProc
        .CommandText = NameOfSproc
    End With

    ' Now execute without using a return value
    With cmdCommand
        .Execute , , adExecuteNoRecords
        .ActiveConnection = Nothing
    End With

    ' And clean up
    Set cmdCommand = Nothing
    Set connConnection = Nothing
    Exit Sub

errorHandler:
    If connConnection.State = adStateOpen Then
        connConnection.Close
    End If
    Set cmdCommand = Nothing
    Set connConnection = Nothing
End Sub
4. Compile the DLL and place it inside a COM+ package. See http://www.aspfree.com/authors/rober...ult.asp?aid=96 for more info on this.

5. Now you can use the DLL as follows in ASP:

Code:
Dim objDataAccess
Set objDataAccess = Server.CreateObject("MyProject.MyClassName")
objDataAccess.ExecSproc("sprocUpdatePrice")
Set objDataAccess = Nothing
As you can see, this is just a very short description of the situation. Of course you'll need more methods, properties etc to make this a successful Data Access component. Methods that you can implement are:

1. ExecSprocReturnRecordset - returns a strongly typed ADODB.Recordset
2. ExecSprocReturnArray - returns a Variant()
3. ExecSprocReturnInteger
4. ExecSQLReturnRecordset - accepts plain SQL instead of a sproc.

You'll also need a way to set up incoming parameters for the procedures.

All this code is based on the FMStocks sample site that Vertigo / Microsoft provided. If you go to http://www.fmstocks.com and download the FMStock 2000 sample project, you'll find all the stuff you need.

It looks like it's time I write a tutorial on how to create a DAL using the FMStock sample as a basis ;)

Cheers,

Imar
 
Old June 10th, 2003, 01:56 AM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That was very usefull thanks a lot :o) Then i have just one question left, when i run a DLL under COM+ do i then not have to restart IIS when i compile my DLL again if there should be a bug in it ?
 
Old June 10th, 2003, 02:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You don't have to restart IIS ever when using COM+ (well, under normal circumstances that is. Sometimes it hangs and needs to be restarted anyway).

Even if you fix a bug all you need to do is follow the steps in the FAQ I posted.

You should also take some time to understand the GUID principle behind COM+ DLLs. If you don't make changes to the interface of your component (add / remove methods, add / remove parameters to existing methods etc) then the GUID for your component stays the same and your component is said to be binary compatible. If you do change the interface, a new GUID is assigned and your component might break (when used in other components / applications).

In both cases, you'll need to stop the package in COM+, remove the components from the package, replace the DLL and then add them again.

HtH

Imar
 
Old June 10th, 2003, 07:27 AM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thats nice to know thanks for your help :o)

And in the meantime i have found this one just if you want to read it, it is also a nice artikle : http://www.asp101.com/articles/carvi...ss/default.asp





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to guess around ActiveX=COM Components asgarcymed VBScript 2 December 3rd, 2007 02:08 PM
ActiveX Components in asp kishore.kumar Classic ASP Components 2 March 9th, 2007 07:53 AM
Advantages /Disadvantages of ActiveX DLL & ActiveX priyank Beginning VB 6 6 February 19th, 2007 11:34 AM
creating an activex dll amc VB Components 7 June 25th, 2004 05:10 PM
ASP & Dll Components byron Pro VB.NET 2002/2003 2 October 15th, 2003 10:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.