473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to make connection strings identical

ad
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?
Mar 26 '06 #1
3 2636
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

"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
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?

Mar 26 '06 #2
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
Mar 26 '06 #3
this explains how to use a config file in your library, different from
web.config:

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

cheers

neil

Mar 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: techimadhu | last post by:
hi, i have a component which creates new sql connectiona and passes the connection object to the clients. i want to implement a connection pool, instead of simply creating infinite number of...
8
by: Natan | last post by:
Hi, I`m creating a asp.net intranet system, and would like to put all the logic of the system in a single dll. That is, when i need to create an user for example, i would use "User.Check()" and...
5
by: Mythran | last post by:
I have a test server and a development machine. I have SQL Server installed on both, the installations are pretty much identical. Both servers are in the same domain. When I run my application...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: PH | last post by:
Hi; I got an application written in ASP.NET (VB.NET and C#) that uses connection pooling. The Max connections defined in the connection command are 50, and there are no more than 3 or 4 user...
0
by: billy.murray | last post by:
I have a system which comprises 4 servers (1 server per plant area). Each plant area server has 2 databases (Config<nand Runtime<nwhere <nis the plant area number) and 1 web application which uses...
12
by: =?Utf-8?B?S2plbGw=?= | last post by:
Hello I've taken a four days training in C#, very good training, experienced teacher and all that, very positive. Went home spent a week making my first application, slightly more than the...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I...
2
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.