Physcial Path of Reference

A

Al

Greetings,

I have several data access class libraries referenced by a web project. I'm
storing the connection string in the data access libraries. I would like an
easier way of moving from my local database server to the production
database than loading every library, changing the connection string to
reflect the new database server address, and recompiling

Since only the database server address would change. I was thinking of
storing the desired database server address in an xml file located in the
bin directory with the other references. When a database call is made, the
correct server address is retrieved from the xml file. However, unlike web
projects, it seems difficult for a class library to determine where it's
located.

Any ideas?

My other concern is the frequency of file operations on the XML file. Any
other ideas.

Thanks in advance.

--


Regards,

Al
 
B

Bruce Barker

web project don't really run from the bin, it copied to temp bin (and
referebced dlls), then compiled, so knowning dir would not be much good, but
you get it from the assembly classes.

put the connection string in the web config (or appconfig if windows app).

-- bruce (sqlwork.com)
 
M

Mythran

Bruce Barker said:
web project don't really run from the bin, it copied to temp bin (and
referebced dlls), then compiled, so knowning dir would not be much good,
but you get it from the assembly classes.

put the connection string in the web config (or appconfig if windows app).

-- bruce (sqlwork.com)


To further explain:

Modify your web.config to add the appSettings section:

<configuration>
...
<appSettings>
<add key="ConnectionString"
value="server=PRODUCTION;database=dbDatabase;trusted_connection=true;" />
</appSettings>
</configuration>


Use something like the following to retrieve the ConnectionString from code:

using System.Configuration;

namespace YourName.Space.Here
{
internal sealed class Configuration
{
private static string mConnectionString;

internal static string ConnectionString
{
get {
return
ConfigurationSettings.AppSettings.Item("ConnectionString");
}
}
}
}

btw, off the top of my head here.

HTH,
Mythran
 
M

Mythran

Bruce Barker said:
web project don't really run from the bin, it copied to temp bin (and
referebced dlls), then compiled, so knowning dir would not be much good,
but you get it from the assembly classes.

put the connection string in the web config (or appconfig if windows app).

-- bruce (sqlwork.com)


To further explain:

Modify your web.config to add the appSettings section:

<configuration>
...
<appSettings>
<add key="ConnectionString"
value="server=PRODUCTION;database=dbDatabase;trusted_connection=true;" />
</appSettings>
</configuration>


Use something like the following to retrieve the ConnectionString from code:

using System.Configuration;

namespace YourName.Space.Here
{
internal sealed class Configuration
{
private static string mConnectionString;

internal static string ConnectionString
{
get {
return
ConfigurationSettings.AppSettings.Item("ConnectionString");
}
}
}
}

btw, off the top of my head here.

HTH,
Mythran
 
A

Al

Greetings,

I was unaware that web.config files could be used in class library projects.
I'll have to try this.

But, each of the data access libraries points to a different SQL database,
on the same database server. Also, some of these data access libraries are
used by more than one project. If I store the predominant connectionstring
in the .config file of the web application, how do I pass that on to the
data access libraries.


Thanks in advance.

--


Regards,

Allen Anderson
 
M

Mythran

Al said:
Greetings,

I was unaware that web.config files could be used in class library
projects. I'll have to try this.

But, each of the data access libraries points to a different SQL database,
on the same database server. Also, some of these data access libraries
are used by more than one project. If I store the predominant
connectionstring in the .config file of the web application, how do I pass
that on to the data access libraries.


Thanks in advance.

--

Class library projects don't have config files themselves. When you use
System.Configuration.ConfigurationSettings.AppSettings, it accesses the
application's configuration file (the application calling the class library
assembly). :)

Mythran
 

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