Instantiere en serviced component???
For at jeg kan instantiere en Serviced Component, skal jeg da lave et Public Interface eller hvordan?Min kode kommer her
Menu.vb er serviced componenten:
<Assembly: ApplicationName("SuperMarket")>
<Assembly: ApplicationActivation(ActivationOption.Library)>
<Assembly: AssemblyKeyFile("KeyFile.snk")>
Namespace Supermarket
'Indicate that this class uses Object Pooling, Transactions are Required, and has an Object Construction String
<ObjectPooling(Enabled:=True, MinPoolSize:=2, MaxPoolSize:=10, CreationTimeout:=20000), Transaction(TransactionOption.Required), JustInTimeActivation(True), ConstructionEnabledAttribute(Default:="data source=MAINFRAME;initial catalog=Supermarket;password=password;persist security info=True;user id=sa;workstation id=MAINFRAME;packet size=4096")> _
Public Class Menu
Inherits ServicedComponent
Private c_sConnectionString As String
Private c_oPooledDataSet As DataSet
Public Sub New()
End Sub
<AutoComplete(True)> _
Public Function GetMenuItems() As DataSet
Dim oCommand As New SqlCommand()
Dim oDataAdapter As New SqlDataAdapter()
c_oPooledDataSet = New DataSet()
With oCommand
.CommandText = "sp_GetMenuItems"
.CommandType = CommandType.StoredProcedure
.Connection = GetConnection()
End With
With oDataAdapter
.SelectCommand = oCommand
.Fill(c_oPooledDataSet, "Menu")
End With
Return c_oPooledDataSet
End Function
Private Function GetConnection() As SqlConnection
Dim oConnection As SqlConnection
Try
oConnection = New SqlConnection(c_sConnectionString)
oConnection.Open()
Return oConnection
Catch ex As Exception
Throw New Exception()
End Try
End Function
End Class
End Namespace
---------------------------------------------------------------------------------
User Control hvor jeg prøver at instantiere den serviced component:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim listIndex As String = Request.Params("tabIndex")
If Not listIndex Is Nothing Then
dlMenu.SelectedIndex = CInt(listIndex)
End If
Dim oMenu As New Supermarket. ?????????????
dlMenu.DataSource = oMenu.GetMenuItems()
dlMenu.DataBind()
End If
End Sub
Hvis der er andre bemærkelsesværdige ting i min kode så hold jer endelig ikke tilbage!
:-D
mvh
DK
