-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: saktiyan
Message 6 in Discussion


I have set the initial lease time of the object to 10 mts.When i try to get the lease 
policy on the first instance i get the problem.The code is as follows:

Singleton object

Public Class Connection
    Inherits System.MarshalByRefObject
    Public Shared Connhits As Integer = 0
    'Public Shared Function getConnection()
    Public Shared Function getConnection() As OleDb.OleDbConnection
        Try
            Dim conn As New OleDb.OleDbConnection
            conn.ConnectionString = "Provider=SQLOLEDB;data source=NT_Server;initial 
catalog=Pubs;user id=sa;pwd="
            conn.Open()
            If conn.State = ConnectionState.Open Then Connhits = Connhits + 1
            Return conn
        Catch e As Exception
            MsgBox(e.Message)
        End Try
    End Function
    Public Overrides Function InitializeLifeTimeService() As Object
        Dim lease As ILease = CType(MyBase.InitializeLifetimeService(), ILease)
        If lease.CurrentState = LeaseState.Initial Then
            lease.InitialLeaseTime = TimeSpan.FromMinutes(10)
            lease.RenewOnCallTime = TimeSpan.FromMinutes(5)
        End If
        Return lease
    End Function
End Class

Host Process

public class HostProcess
        {
                public HostProcess()
                {
                        //
                        // TODO: Add constructor logic here
                        //
                }
                public static void Main()
                {
                        TcpChannel Channel = new TcpChannel(10000);
                        ChannelServices.RegisterChannel(Channel);
                        RemotingConfiguration.ApplicationName="Data Connection";
                        
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Dataconnection.Connection),"Connection",WellKnownObjectMode.Singleton);
                        
                }
        }

Client Application (Windows Application)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles Button1.Click
        Dim objConn As New Connection
        Dim Conn As OleDb.OleDbConnection
        Conn = objConn.getConnection()
        MsgBox(objConn.Connhits)
        Dim lease As ILease = CType(objConn.GetLifetimeService(), ILease)
        MsgBox(lease.RenewOnCallTime)
        'MsgBox(objConn.Connhits)
        'MsgBox(objConn.Timerenew)
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
Handles MyBase.Load
        
RemotingConfiguration.RegisterWellKnownClientType(GetType(Dataconnection.Connection), 
url)
    End Sub

i hope this will be of soe use to you

Regards

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to