On Sun, 26 Mar 2006 22:48:27 +0800, "ad" <fl****@wfes.tcc.edu.tw> wrote:
I have a web application which refer a class library project.
The web application have a web.config and the class library project have a
app.config.
They all have connection string defined in them.
I set both connection strings identical in VS2005.
But after publish it to web site, I can just set the connection in the web
application.
How can I set the app.config in the class library after publish?
In the class library, make an overloaded constructor that takes a connection
string as a parameter:
/// <summary>
/// Data access methods for the USCities table
/// </summary>
public class USCityTable
{
private string _connectionString;
#region ctors
/// <summary>
/// Initialization ctor
/// </summary>
/// <param name="connectionString">Database connection string</param>
public USCityTable(string connectionString)
{
_connectionString = connectionString;
}
#endregion ctors
#region public methods
/// <summary>
/// Select all cities in the USCities table
/// </summary>
public USCities SelectAllCities()
{
SqlConnection cn = new SqlConnection(_connectionString);
SqlCommand cmd = new SqlCommand("sp_FetchAllCities", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = null;
USCities cities = new USCities();
After retrieving the connection string from the web.config file set the
connection string for the class like this:
USCityTable citytable = new USCityTable("yourConnectionString");
Otis Mukinfus
http://www.arltex.com http://www.tomchilders.com