473,783 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TableAdapters and web.config

I have a class library that contains a number of TableAdapters and I'm using
this from a web application. Is there a way of getting the TableAdapters to
use the connectionstrin gs defined in web.config.

From the MSDN documentation it seems like it's possible to override settings
with values in a config file for winform applications. Is the same possible
for web applications.

I have tried to add a connectionstrin g (under the connectionstrin g section)
in web.config with the same name as the name in the setting file. The
connectionstrin g in web.config points to a database that doesn't contain the
required schema. Since I'm not getting any errors and things are still
working, I assume it is still using the default connectionstrin g supplied at
designtime.

Nov 19 '05 #1
3 4267
Hi Kimbell,

Welcome to ASP.NET newsgroup.
Regarding on the configuration issue you mentioned when using TableAdapter
from class library in asp.net 2.0 project, I've also met this problem
before. Yes, as you has mentioned, when we has build the
DataSet/TableAdapter in class library project, the TableAdapter's
Connection /ConnectionStrin g setting is persisted in the classlibrary
assembly's content so that when referenced in asp.net 2.0 project, it won't
use the web.config file's info (but still use the one persisted at
design-time in classlibrary project). Based on my research, as for the
Project Settings, the asp.net 2.0 seems has different support from winform
project. Currently one approach is manually modify the TableAdapter's
design-time generated code in the Classlibrary project. for example:

the TAbleAdapter's autogenerate code is as below, the "InitConnection "
function is just the one which supply connectionstrin g and constructing the
Connection instance for the TableAdapter

=============== ==============
private void InitConnection( )
{
this.m_connecti on = new System.Data.Sql Client.SqlConne ction();
this.m_connecti on.ConnectionSt ring =
DSLibrary.Prope rties.Settings. Default.Northwi ndConnectionStr ing;
}

which retrieve the connection string through Project's Properties.Sett ings
collection. We can modify it to the following one:

=============== =======

Object obj =
System.Configur ation.Configura tionSettings.Ge tConfig("connec tionStrings");
ConnectionStrin gsSection css = obj as ConnectionStrin gsSection;
string connstr =
css.ConnectionS trings["LocalNorthwind ConnStr"].ConnectionStri ng;
this.m_connecti on = new System.Data.Sql Client.SqlConne ction();
this.m_connecti on.ConnectionSt ring = connstr;

=============== ======

so that it will retrieve the info from the final hosting application's
application config file (appconfig or web.config).

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security

--------------------
| Thread-Topic: TableAdapters and web.config
| thread-index: AcXNckyfTDC6JTs kQe231gX8p+7Y9A ==
| X-WBNR-Posting-Host: 195.139.24.170
| From: "=?Utf-8?B?Q2hyaXN0b3B oZXIgS2ltYmVsbA ==?="
<c_*******@news group.nospam>
| Subject: TableAdapters and web.config
| Date: Mon, 10 Oct 2005 01:12:04 -0700
| Lines: 15
| Message-ID: <69************ *************** *******@microso ft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA03.phx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3496 11
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| I have a class library that contains a number of TableAdapters and I'm
using
| this from a web application. Is there a way of getting the TableAdapters
to
| use the connectionstrin gs defined in web.config.
|
| From the MSDN documentation it seems like it's possible to override
settings
| with values in a config file for winform applications. Is the same
possible
| for web applications.
|
| I have tried to add a connectionstrin g (under the connectionstrin g
section)
| in web.config with the same name as the name in the setting file. The
| connectionstrin g in web.config points to a database that doesn't contain
the
| required schema. Since I'm not getting any errors and things are still
| working, I assume it is still using the default connectionstrin g supplied
at
| designtime.
|
|

Nov 19 '05 #2
So what you are recommending is to change the autogenerated code?
What about the following warning at the top of the file:

"Changes to this file may cause incorrect behavior and will be lost if the
code is regenerated."

Particularly the statement about lost changes.

I think a better approach is to change the ConnectionModif ier to public in
the designer; then set the connectionstrin g from code.

I was hoping for a more elegant solution since Microsoft has put some work
into this settings system. Maybe in the next version.
"Steven Cheng[MSFT]" wrote:
Hi Kimbell,

Welcome to ASP.NET newsgroup.
Regarding on the configuration issue you mentioned when using TableAdapter
from class library in asp.net 2.0 project, I've also met this problem
before. Yes, as you has mentioned, when we has build the
DataSet/TableAdapter in class library project, the TableAdapter's
Connection /ConnectionStrin g setting is persisted in the classlibrary
assembly's content so that when referenced in asp.net 2.0 project, it won't
use the web.config file's info (but still use the one persisted at
design-time in classlibrary project). Based on my research, as for the
Project Settings, the asp.net 2.0 seems has different support from winform
project. Currently one approach is manually modify the TableAdapter's
design-time generated code in the Classlibrary project. for example:

the TAbleAdapter's autogenerate code is as below, the "InitConnection "
function is just the one which supply connectionstrin g and constructing the
Connection instance for the TableAdapter

=============== ==============
private void InitConnection( )
{
this.m_connecti on = new System.Data.Sql Client.SqlConne ction();
this.m_connecti on.ConnectionSt ring =
DSLibrary.Prope rties.Settings. Default.Northwi ndConnectionStr ing;
}

which retrieve the connection string through Project's Properties.Sett ings
collection. We can modify it to the following one:

=============== =======

Object obj =
System.Configur ation.Configura tionSettings.Ge tConfig("connec tionStrings");
ConnectionStrin gsSection css = obj as ConnectionStrin gsSection;
string connstr =
css.ConnectionS trings["LocalNorthwind ConnStr"].ConnectionStri ng;
this.m_connecti on = new System.Data.Sql Client.SqlConne ction();
this.m_connecti on.ConnectionSt ring = connstr;

=============== ======

so that it will retrieve the info from the final hosting application's
application config file (appconfig or web.config).

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support


Nov 19 '05 #3
Thanks for your response Kimbell,

Yes, the
========
"Changes to this file may cause incorrect behavior and will be lost if the
code is regenerated."
========
you mentioned is really a potential problem with my workaround. And your
appoarch on changing the ConnectionModif er to public is OK for
programmatical accessing. However, in most cases of ASP.NET 2.0 web
application, we will use design-time ObjectDataSourc e control to reference
the TableAdpater, and this is done through IDE interactively no code is
involved. So in such scenario, we may need to predefined the connection's
initilization in TableAdapter's code.

Anyway, I really appreciate your advice on the configuration setttings ,
and since this is a new feature involved in 2.0, I think it'll be improved
in the sequential versions so as to ease the component, class library
developing and seamless integrated into
front end applications.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
--------------------
| Thread-Topic: TableAdapters and web.config
| thread-index: AcXOO+CVs5sRlZY tRh+M2u+nQzNUBg ==
| X-WBNR-Posting-Host: 195.139.24.170
| From: "=?Utf-8?B?Q2hyaXN0b3B oZXIgS2ltYmVsbA ==?="
<c_*******@news group.nospam>
| References: <69************ *************** *******@microso ft.com>
<o4************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: RE: TableAdapters and web.config
| Date: Tue, 11 Oct 2005 01:15:01 -0700
| Lines: 68
| Message-ID: <EA************ *************** *******@microso ft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA01.phx.gbl!T K2MSFTNGXA03.ph x.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3498 77
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| So what you are recommending is to change the autogenerated code?
| What about the following warning at the top of the file:
|
| "Changes to this file may cause incorrect behavior and will be lost if
the
| code is regenerated."
|
| Particularly the statement about lost changes.
|
| I think a better approach is to change the ConnectionModif ier to public
in
| the designer; then set the connectionstrin g from code.
|
| I was hoping for a more elegant solution since Microsoft has put some
work
| into this settings system. Maybe in the next version.
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Kimbell,
| >
| > Welcome to ASP.NET newsgroup.
| > Regarding on the configuration issue you mentioned when using
TableAdapter
| > from class library in asp.net 2.0 project, I've also met this problem
| > before. Yes, as you has mentioned, when we has build the
| > DataSet/TableAdapter in class library project, the TableAdapter's
| > Connection /ConnectionStrin g setting is persisted in the classlibrary
| > assembly's content so that when referenced in asp.net 2.0 project, it
won't
| > use the web.config file's info (but still use the one persisted at
| > design-time in classlibrary project). Based on my research, as for the
| > Project Settings, the asp.net 2.0 seems has different support from
winform
| > project. Currently one approach is manually modify the TableAdapter's
| > design-time generated code in the Classlibrary project. for example:
| >
| > the TAbleAdapter's autogenerate code is as below, the "InitConnection "
| > function is just the one which supply connectionstrin g and constructing
the
| > Connection instance for the TableAdapter
| >
| > =============== ==============
| > private void InitConnection( )
| > {
| > this.m_connecti on = new System.Data.Sql Client.SqlConne ction();
| > this.m_connecti on.ConnectionSt ring =
| > DSLibrary.Prope rties.Settings. Default.Northwi ndConnectionStr ing;
| > }
| >
| > which retrieve the connection string through Project's
Properties.Sett ings
| > collection. We can modify it to the following one:
| >
| > =============== =======
| >
| > Object obj =
| >
System.Configur ation.Configura tionSettings.Ge tConfig("connec tionStrings");
| > ConnectionStrin gsSection css = obj as ConnectionStrin gsSection;
| > string connstr =
| > css.ConnectionS trings["LocalNorthwind ConnStr"].ConnectionStri ng;
| > this.m_connecti on = new System.Data.Sql Client.SqlConne ction();
| > this.m_connecti on.ConnectionSt ring = connstr;
| >
| > =============== ======
| >
| > so that it will retrieve the info from the final hosting application's
| > application config file (appconfig or web.config).
| >
| > Hope helps. Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
|
|

Nov 19 '05 #4

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

Similar topics

0
954
by: spooke | last post by:
HI all now are two days, 20 hours of work that i'm on this problem without a solution!!! I think i'll become mad!!! Here is the problem: I Use C# 2.0 (VS .Net 2005) with thyped dataset I Make my connection and the connection generates the DataTables and the TableAdapters
7
1390
by: CMM | last post by:
Unless someone has come up with a way, I still don't understand how you can use TableAdapters in a true n-tier infrastructure.... where the DataAccessLayer is in one Dll and *only* the Datasets themselves can be shared across layers. I find it inconceivable that this suggestion http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=d2907b53-885b-4d24-bc9c-1a04d76036e4 (that's not me who suggested it) has been marked...
2
2314
by: Nick Hustak | last post by:
Hi, I've been trying to work with the XSDs and ran into a few road blocks. 1. Stored procedures that uses temp tables, i.e. #TempTable. The wizard complains that #TempTable is an invalid object. What gives? 2. How do you programatically change the connection string at runtime when using these TableAdapters via databinding in the IDE GUI? Thanks,
0
990
by: rswafford | last post by:
Hi, I am beginning to rewrite an application in ASP.NET 2.0, and I want to utilize strongly typed TableAdapters for my data access layer. However the database that gets queried is not known until the user is logged in -- each client using this application has their own database on my company's server. I know that the SqlConnection object in C# has a ChangeDatabase() method that allows you to specify what database to connect to at...
3
2639
by: Martyn Fewtrell | last post by:
Hi there. First of all let me apologise for this is a somewhat general question to which I would be interested in any opinions. As far as I can see when I create a web application the recommended location for the database is the app_data folder. The recommended location for code files and datasets/table adapters appears to be the app_code folder. This set up appears to work reasonably well although it results in the all the code...
4
2522
by: Ted Ngo | last post by:
I create a northwind Strongly Typed TableAdapters dataset, the create a query like "select a, b, c, d from employeetable" then bind it into the gridview dim t as new northwindTableAdapters gridview1.datasource = t.getdata() gridview1.databind() Now I create new query in the TableAdapters dataset
1
1848
by: Brett Romero | last post by:
I store my server and database names in a static class that all libraries use. Using a config file, I can switch from test, staging, or production servers easily. I like what TableAdapters are generated by VS.NET 2005 do. It seems most everything is there for you. However, because the TableAdapter controls everything, I'll have to go to each and change the connection string when I want to switch servers. Or, am I missing something? ...
7
2494
by: =?Utf-8?B?R3JlZw==?= | last post by:
When using the VS Wizards to create a DataSet I select tables. Then, I use the TableAdapter Configuration Wizard to modify the underlying queries that retreive the data. What I'm wonder is, does this TableAdapter work in the same manner as a SQL Server Stored Procedure or View? Or, does it work like MS Access where it pulls all the data over and then filters it? Or, should I be making my data sources for the TableAdapters stored...
0
1198
by: tiger00555 | last post by:
in reference to the below thread: http://bytes.com/groups/net-asp/344508-tableadapters-web-config does this issue still exist in visual studio 2008? I guess having a build environment with rewrite scripts for the project settings changing the database connection string during compile time is another way to alleviate this issue.
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.