Solved

DLL in VB.net

Posted on 2003-11-19
13
926 Views
Last Modified: 2008-02-01
I made a DLL which checks the for a column in a database in SQL Server. The DLL is made in VB.NET.
I then made a Setup using ADD PROJECT --> Setup and Deployment --> Windows setup and added the dependency files etc.
Thus I got the installer and then I installed it on my server.

When using this DLL in the ASP page, I do the following :

      'asp code
      Dim x
      Set x = Server.CreateObject("D_V.D_V")
      x.functionname("parameter")
      Response.Write(x.propertyname)
      x=nothing

On running the test page, i get the following error :

Error Type:
Server object, ASP 0177 (0x800401F3)
Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp.

Pls help.
Thanks,
DEeL
0
Comment
Question by:digitaleel
  • 4
  • 3
  • 2
  • +1
13 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9779818
Set x = Server.CreateObject("D_V.D_V")
     x.functionname("parameter")
     Response.Write(x.propertyname

this approach assumes that the DLL is COM-compliant, but .NET DLLs are NOT COM (Component Object Model) DLLs.  YOu need to create a COM-Wrapper for your .NET DLL.

why are you using ASP, rather than ASP.NET?  If you used ASP.NET for the web pages, then you simply instantiate an object in VB.NET code, in the code-behind for the ASPX page.

AW
0
 

Author Comment

by:digitaleel
ID: 9779921
I need to make sure that this particular DLL can be used from VB6, ASP, ASP.net as well as VB.NET .. all it uses is a database connection and a stored procedure. The DLL should work perfectly with all of the above..because I have different applications in each of the technologies..and this is a standard DLL to be used everywhere...
Whats with the wrapper ? I don't know bout it.
Thanks,
DeEl
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 9780467
Include a library (like office 10) in your code and you will see a COM wrapper created.  Something like Interop.something.somthing
0
 

Author Comment

by:digitaleel
ID: 9780711
Well, before I did that, I already tried this in my COM component
This is my dll..

<ComClass(D_V.ClassId, D_V.InterfaceId, D_V.EventsId)> _
Public Class D_V Inherits EnterpriseServices.ServicedComponent

#Region "COM GUIDs" 'all generated using the GUID tool
 Public Const ClassId As String = "498B3B00-710C-4c4e-96D9-59509E1F2EE9"
    Public Const InterfaceId As String = "E807E7EE-9146-47ee-B4C2-C8751D5492EE"
    Public Const EventsId As String = "B6F5A029-D03C-4683-87EA-4A224BED5DA0"
#End Region

 Public Sub New()
        MyBase.New()
    End Sub

Private vVar As String
Public pVar As String

Public Property PvVar() As String
        Get
            Return vVar
        End Get
        Set(ByVal pvar As String)
            vVar = pvar
        End Set
    End Property

 Public Sub myfunction(ByVal param As String)

 Dim cn

        Try
            cn = New SqlConnection(GetConnectionString())
            cn.Open()

        Catch ex As SqlException

            'send notification
                  End Try


 Try
            '-- create command and set stored procedure parameters
            'open recordset and get values
            Dim cmd As New SqlCommand("mysp", cn)
            cmd.CommandType = CommandType.StoredProcedure
           Dim dr As SqlDataReader
          With cmd
                .CommandType = CommandType.StoredProcedure
                .Parameters.Add("@sp_parameter", SqlDbType.VarChar, 50).Value = param
                .Prepare()
            End With

            dr = cmd.ExecuteReader
           
            While dr.Read
              If Not IsDBNull(dr.Item("column1")) Then pvar = dr.Item("column1")
            End While

            dr.Close()
            dr = Nothing
            cmd.Cancel()
            cmd = Nothing
            Catch SQLException As SqlException
            '-- error handling
           Finally

        End Try

.................apart from this, i have added the following in my assemblyinfo.vb

'COM+
<Assembly: ApplicationActivation(ActivationOption.Server)>
<Assembly: ApplicationName("myappname")>

I build this solution, and then build an installer using deployment project stuff..then i run the installer setup on the server, and try the dll on the asp page..
also, when i try to use it in VB, even though i installed the dll, in VB6->Add Reference-> I cannot see my Dll or com component..and when i browse to select the particular dll in the installed directory, it does not allow me to do so :
Project->Add Reference->Browse->select the dll...gives the error "Can't add reference to the specified file"

phew..I am pi*^%d off...SOS~~~~
Thanks,,
DeEl


    End Sub
0
 
LVL 12

Accepted Solution

by:
vascov earned 250 total points
ID: 9807392
Hi,

Ignoring the setup issues for now... here's what you have to do to make your .NET class creatable and callable by COM.
* make it a strong name assembly, because it will have to go into de GAC (using gacutil.exe for instance)
* then, regasm.exe to export the types into the COM registry, so that COM knows that your object exists

If you are not going to use any Enterprise Services (COM+), then don't place your object in a COM+ Application, that will just add overhead. You can still call your .NET object from COM without using Enterprise Services. That said, if you want to use Enterprise Services, the procedure is very much the same.

Using part of the code you sent, i created the following:

Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic

<Assembly: AssemblyKeyFile( "mykey.snk" )>

<ComClass(D_V.ClassId, D_V.InterfaceId, D_V.EventsId), ProgId( "MyCompany.MyProject.D_V" )> _
Public Class D_V

      #Region "COM GUIDs" 'all generated using the GUID tool
            Public Const ClassId As String = "498B3B00-710C-4c4e-96D9-59509E1F2EE9"
            Public Const InterfaceId As String = "E807E7EE-9146-47ee-B4C2-C8751D5492EE"
            Public Const EventsId As String = "B6F5A029-D03C-4683-87EA-4A224BED5DA0"
      #End Region

      Public Sub New()
              MyBase.New()
      End Sub

      Public Sub myfunction(ByVal param As String)
            Dim cn As System.Data.SqlClient.SqlConnection

            Try
                  cn = New SqlConnection( "Integrated Security=SSPI;Initial Catalog=master;Data Source=(local);" )
                  cn.Open()
            Catch ex As SqlException
                  System.Diagnostics.Debug.WriteLine( ex.ToString() )
            Finally
                  cn.Close()
            End Try

      End Sub
End Class

The AssemblyKeyFile signals that it should use a key i generated previously using:
sn -k mykey.snk
to make the assembly strong named

The Attribute ProgId gives an explicit progid for this component.

I used the following cmd-line to compile the previous assembly
vbc /out:mycomp.dll /t:library mycomp.vb /r:System.dll,System.Data.dll

Then, i had to register this with COM, using regasm.exe
regasm mycomp.dll

And finally, because COM instantiations can come from any dir on the disk, and .NET will have to find my assembly, i had do place this assembly in the GAC, using:
gacutil -i mycomp.dll

So now:
* my types are published in the COM registry
* my types are available to any .NET app

you can create a simple .vbs file to test this:
Set o = CreateObject( "MyCompany.MyProject.D_V" )
Call o.myfunction( "something" )


Regarding your setup app, you'll have to eventually create a custom action that regasm's and put's the assembly in the GAC

HTH
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:vascov
ID: 9889679
Is it working !?
0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 9894328
Get used to it vascow.

I'm just now getting points from questions I answered in June :)
0
 
LVL 12

Expert Comment

by:vascov
ID: 9895958
:)

starting to get used :)


0
 
LVL 5

Expert Comment

by:TRUENEUTRAL
ID: 10321951
Did you ever get a solution working?
0
 
LVL 12

Expert Comment

by:vascov
ID: 10322187
Hi trueneutral and digitaleel

I hope that digitaleel got it working. The code i sent him sure did :)

Vasco
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now