Groups | Blog | Home
all groups > asp.net > march 2006 >

asp.net : How to make connection strings identical


Otis Mukinfus
3/26/2006 9:59:40 AM
[quoted text, click to view]
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
neilmcguigan NO[at]SPAM gmail.com
3/26/2006 10:41:31 AM
this explains how to use a config file in your library, different from
web.config:

http://www.bearcanyon.com/dotnet/#AssemblySettings

cheers

neil
Eliyahu Goldin
3/26/2006 5:57:54 PM
A class library shouldn't care whether configuration parameters reside in a
web.config or an app.config file. What file is used depends on the platform.
For Windows it will be app.config, for web - web.config. You can't use both.

Eliyahu

[quoted text, click to view]

ad
3/26/2006 10:48:27 PM
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?

AddThis Social Bookmark Button