Settings Question

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
 
C

Cor Ligthert [MVP]

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
 
K

Kent Boogaart

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
 
C

Cor Ligthert [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top