Settings Question

  • Thread starter Thread starter Kent Boogaart
  • Start date Start date
K

Kent Boogaart

Hi,

I am working on a web project and have split my data access layer into a
separate DLL. This separate DLL uses a .settings file to store the
connection string. A strongly-typed settings class is generated for me in
the background. However, this generated class is internal.

My problem is that I need to get to the connection string from the web
project in order to configure my logging subsystem (which logs to the DB).
Now, I can think of an obvious hack around this. I could just put something
like this in my DAL DLL:

public static class ConnectionDetails
{
public static string ConnectionString
{
get
{
//the Settings class is internal
return Settings.Default.MyConnectionString;
}
}
}

What I'm wondering is whether there is a better solution to this. Have I
overlooked something obvious here?

Thanks,
Kent
 
Kent,

In 2.0 is the connectionstring when using the designer placed in the
app.config with a windowsform application.

Windowsform version
<connectionStrings>
<add
name="WindowsApplication1.My.MySettings.NorthwindConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\test1\Northwind.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>

Which than can be used in VBNet as
Me._connection.ConnectionString =
Global.WindowsApplication1.My.MySettings.Default.NorthwindConnectionString

And in C#

this._connection.ConnectionString =
global::WindowsApplication1.Properties.Settings.Default.NorthwindConnectionString;

I hope this helps,

Cor
 
Hi Cor, thanks for the reply. Unfortunately, that does not help me because
my .settings file is in a DLL, not an application. Therefore, I need a way
to open the configuration for the DLL from my web project. The
ConfigurationManager class does not have such a method. Do you know if this
is possible?

Thanks,
Kent
 
Kent,

I have tried this, I have made in the same way a class library and used that
in my webapplication.

No problem at all.

Cor
 
Back
Top