Accessing database from another machine

Accessing database from another machine

Old forum URL: forums.lhotka.net/forums/t/3357.aspx


kc123 posted on Thursday, August 09, 2007

Hi,

I have done 2 csla projects so far and both are in a single machine, meaning the UI layer, BO layer and the database are all in a single machine.

Recently we are going to do a csla project at work and the database is in a separate server.  So I modify the app.config file to look like this


<add name="VIP3Connection"
             ConnectionString="Data Source=139.69.2.70,1433; Network Library=DBMSSOCN; Initial Catalog=TestDatabase; user id=sa; password=;"
             ProviderName="System.Data.SqlClient"/>

where 139.69.2.70 is the IP address of the database server.

When I run it, I got a "Configuration system failed to initialized" error when the program is trying to access the ConfigurationManager.AppSettings("CslaDataPortalProxy").  Does anybody knows that what other step(s) that I am missing here?

Your help will be highly appreciated!

KC

JoeFallon1 replied on Thursday, August 09, 2007

My config file looks like this:

<appSettings>
  <add key="ConnectionString" value="data source=myServer;database=someDB;User ID=myAppUser;password=somePwd" />
  <add key="CslaAuthentication" value="CSLA" />
</appSettings>

The ApplicationContext module looks in the config file for the setting: key="CslaDataPortalProxy".

If it does not find it then it configures the DataPortal as Local.

Public ReadOnly Property DataPortalProxy() As String
Get
  Dim result As String = ConfigurationManager.AppSettings("CslaDataPortalProxy")
  If Len(result) = 0 Then
    result = "Local"
  End If
  Return result
End Get
End Property

Joe

 

kc123 replied on Thursday, August 09, 2007

Thanks for your pointer.  You gave me some idea so at least now I can read from the database, although I am not doing it right (hard coding instead of reading from the app.config file)

In Rocky's code, he put the connection string in the connectionStrings node of the app.config file instead of in the appSettings node of the app.config file, like in your example.  Then he has a Module named Database and has two string properties of ConnectionString for the program to read from.  Thats what I did and I am getting error.

But when I hard coded the connection string into the property, it works, I can read from the database.

Here are the relevant code that does not work:

Imports System.Configuration.ConfigurationManager
Public Module Database
    Public ReadOnly Property VIP3Connection() As String
        Get
            Return ConnectionStrings("VIP3Connection").ConnectionString
        End Get
    End Property
End Module


Then in the app.config file, I have:

<ConnectionStrings>
    <add name="VIP3Connection"
             ConnectionString="Data Source=139.69.2.70,1433; Network Library=DBMSSOCN; Initial Catalog=TestDatabase; user id=sa; password=;"
             ProviderName="System.Data.SqlClient"/>
  </ConnectionStrings>


But when I do this, it work:

Public Module Database
    Public ReadOnly Property VIP3Connection() As String
        Get
            Return "Data Source=139.69.2.70,1433; Network Library=DBMSSOCN; Initial Catalog=TestDatabase; user id=sa; password=;"
        End Get
    End Property
End Module

Plus commenting out the ConnectionStrings node in the app.config file.

So for some reason I have trouble reading from the app.config file.

KC

Copyright (c) Marimer LLC