How can I gen connection string in config file from server?

Please help me !

How can I get connection string in web.config file from server when Remote Object has been registed on IIS

The code details:

Remote Object:

Imports System.Runtime.Remoting

Imports System.Runtime.Remoting.Channels.Http

Public Class CustomerObject

Inherits System.MarshalByRefObject

Private m_strConnectionString As String

Sub New()

m_strConnectionString = System.Configuration.ConfigurationSettings.AppSettings("CNN_STR")

End Sub

Public ReadOnly Property ConnectionString() As String

Get

Return m_strConnectionString

End Get

End Property

End Class

Cilent.config:

< xml version="1.0" encoding="utf-8" >

<configuration>

<system.runtime.remoting>

<application name="Client">

<client url="http://localhost/CustomerObject">

<wellknown type="RemoteObject.CustomerObject, CustomerObject"

url="http://localhost/CustomerObject.soap"/>

</client>

<channels>

<channel ref="http" />

</channels>

</application>

</system.runtime.remoting>

</configuration>

Web.config

< xml version="1.0" encoding="utf-8" >

<configuration>

<system.runtime.remoting>

<application>

<service>

<wellknown mode="SingleCall" type="RemoteObject.CustomerObject, CustomerObject" objectUri="CustomerObject.soap" />

</service>

</application>

</system.runtime.remoting>

<appSettings>

<add key="CNN_STR" value="server=.;database=northwind;uid=sa;pwd=" />

</appSettings>

</configuration>

I create virtual directory server and create sub folder bin, the direcroty has included RemoteObject.dll file. Then I copy web.config to server folder.

Client:

Imports System.Runtime.Remoting

Imports System.Runtime.Remoting.Channels.Http

Imports RemoteObject

Module Module1

Sub Main()

Try

Console.WriteLine("Config Remote Object...")

'Load the Http Channel from the config file

RemotingConfiguration.Configure("Client.config")

Console.WriteLine("Create instance of remote object...")

'instantiate the remote object on the server

'(this is really just a proxy object here)

Dim objRemote As RemoteObject.CustomerObject = New RemoteObject.CustomerObject

If (objRemote.ConnectionString = Nothing) Then

Console.WriteLine("Connection string is nothing !")

Else

Console.WriteLine(String.Format("Connection string: {0}", objRemote.ConnectionString))

End If

Console.WriteLine("Press any key to exit !")

Console.ReadLine()

Catch ex As Exception

Console.WriteLine(ex.Message)

Console.ReadLine()

End Try

End Sub

End Module

When Client run, message Connection string is nothing ! has been writed on screen. It's mean Remote Object can get value of key CNN_STR in web.config file.

Please help me!!!!!!!!!!!!




Answer this question

How can I gen connection string in config file from server?

  • Steve Watts

    I have been created a web application but It return the same result. Please help me....................

  • craig1972

    Have you created a Web Application in that vroot

  • funti

    Manh, can you try printing out the connection string on the service side to make sure your configuration call is completing successfully

    Regards,

    JJustice [MSFT]


  • RpM

    I have been printing out the connection string but it's nothing. What do I have to do for this work Please help me......

  • Webman

    Ok, It works now. Thanks a lot. I must call Activator.GetObject() to get from server, which has been registed on IIS.

  • How can I gen connection string in config file from server?