473,385 Members | 1,546 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,385 software developers and data experts.

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 connectionstrings 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 connectionstring (under the connectionstring section)
in web.config with the same name as the name in the setting file. The
connectionstring 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 connectionstring supplied at
designtime.

Nov 19 '05 #1
3 4240
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 /ConnectionString 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 connectionstring and constructing the
Connection instance for the TableAdapter

=============================
private void InitConnection()
{
this.m_connection = new System.Data.SqlClient.SqlConnection();
this.m_connection.ConnectionString =
DSLibrary.Properties.Settings.Default.NorthwindCon nectionString;
}

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

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

Object obj =
System.Configuration.ConfigurationSettings.GetConf ig("connectionStrings");
ConnectionStringsSection css = obj as ConnectionStringsSection;
string connstr =
css.ConnectionStrings["LocalNorthwindConnStr"].ConnectionString;
this.m_connection = new System.Data.SqlClient.SqlConnection();
this.m_connection.ConnectionString = 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: AcXNckyfTDC6JTskQe231gX8p+7Y9A==
| X-WBNR-Posting-Host: 195.139.24.170
| From: "=?Utf-8?B?Q2hyaXN0b3BoZXIgS2ltYmVsbA==?="
<c_*******@newsgroup.nospam>
| Subject: TableAdapters and web.config
| Date: Mon, 10 Oct 2005 01:12:04 -0700
| Lines: 15
| Message-ID: <69**********************************@microsoft.co m>
| 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.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:349611
| X-Tomcat-NG: microsoft.public.dotnet.framework.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 connectionstrings 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 connectionstring (under the connectionstring
section)
| in web.config with the same name as the name in the setting file. The
| connectionstring 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 connectionstring 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 ConnectionModifier to public in
the designer; then set the connectionstring 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 /ConnectionString 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 connectionstring and constructing the
Connection instance for the TableAdapter

=============================
private void InitConnection()
{
this.m_connection = new System.Data.SqlClient.SqlConnection();
this.m_connection.ConnectionString =
DSLibrary.Properties.Settings.Default.NorthwindCon nectionString;
}

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

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

Object obj =
System.Configuration.ConfigurationSettings.GetConf ig("connectionStrings");
ConnectionStringsSection css = obj as ConnectionStringsSection;
string connstr =
css.ConnectionStrings["LocalNorthwindConnStr"].ConnectionString;
this.m_connection = new System.Data.SqlClient.SqlConnection();
this.m_connection.ConnectionString = 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 ConnectionModifer to public is OK for
programmatical accessing. However, in most cases of ASP.NET 2.0 web
application, we will use design-time ObjectDataSource 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+CVs5sRlZYtRh+M2u+nQzNUBg==
| X-WBNR-Posting-Host: 195.139.24.170
| From: "=?Utf-8?B?Q2hyaXN0b3BoZXIgS2ltYmVsbA==?="
<c_*******@newsgroup.nospam>
| References: <69**********************************@microsoft.co m>
<o4**************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: TableAdapters and web.config
| Date: Tue, 11 Oct 2005 01:15:01 -0700
| Lines: 68
| Message-ID: <EA**********************************@microsoft.co m>
| 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.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:349877
| X-Tomcat-NG: microsoft.public.dotnet.framework.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 ConnectionModifier to public
in
| the designer; then set the connectionstring 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 /ConnectionString 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 connectionstring and constructing
the
| > Connection instance for the TableAdapter
| >
| > =============================
| > private void InitConnection()
| > {
| > this.m_connection = new System.Data.SqlClient.SqlConnection();
| > this.m_connection.ConnectionString =
| > DSLibrary.Properties.Settings.Default.NorthwindCon nectionString;
| > }
| >
| > which retrieve the connection string through Project's
Properties.Settings
| > collection. We can modify it to the following one:
| >
| > ======================
| >
| > Object obj =
| >
System.Configuration.ConfigurationSettings.GetConf ig("connectionStrings");
| > ConnectionStringsSection css = obj as ConnectionStringsSection;
| > string connstr =
| > css.ConnectionStrings["LocalNorthwindConnStr"].ConnectionString;
| > this.m_connection = new System.Data.SqlClient.SqlConnection();
| > this.m_connection.ConnectionString = 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
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...
7
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...
2
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...
0
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...
3
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...
4
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...
1
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...
7
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...
0
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...
1
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.