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

ASP.Net website structure - TableAdapters and a Class Library

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
files being published with the web application.

A better solution appears to be to create a separate Class Library with a
reference to that Library from the web applications. After a build the dll is
copied into the bin folder and any of the code can be accessed just fine.
With this set up I only then need to publish the dll in the bin folder which
seems a better option.

With the second option everything is fine just so long as I use SQL Server
as the location of the database is not critical to the connection string.
However if I want to use an Access Database (well I don’t want to but
sometimes this is the only option) the access database is located in the
app_data folder which isn’t naturally accessible from the Class Library. If I
create a dataset with table adapters within the class library when I compile
the project the connection string appears to be wrong as the dll copied to
the web application doesn’t look for the string details in the web.config.
Previously it was using the connection string from the application settings.

The conclusion I have drawn is that using table adapters in an external
Class Library to create a data layer doesn’t work so well with an Access
database.

Is this correct or am I missing something?

Any good articles covering the above would be of interest.

--
Regards

Martyn Fewtrell
Sep 12 '06 #1
3 2622
Hello Martyn,

From your description, the problem you met here is the
TypedDataSet/TableAdapter(defined in a separate class library project)
which connect to an Access mdb file will not quite work when referenced in
ASP.NET web application since the TableAdapter will still refer to the
original database connectionstring(file path) to mdb file used at
design-time, correct?

I think what you do here is correct and it is certainly reasonable to
separate the TypedDataSet/TableAdapter(or other custom data access/business
component) into separate class library when we want to provide good
encapsulation and isolation of differnt Tier in our application. The reason
why the TableAdapter will reference the connectionstring(file path) at
design-time is because VS IDE will help generate a setting class which
contains a dictionary of data, and the TableAdapter's connectionstring is
also stored in it. However, this value is overridable if we use the class
library in other upstream application layer(in asp.net or winform
application), this can be done through override the connectionString in the
upstream application's application config file(web.config for asp.net
application). Actually, in the class library project, you will find an
"app.config" file also, and it will contains the connectionstring entry for
the TableAdapter, e.g.

===================
<add name="URLSiteLib.Properties.Settings.AccessDBConne ctionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=D:\temp\database_temp\aspdb.mdb"
providerName="System.Data.OleDb" />
===================

this is the one you set when creating the DataSet/Tableadapter, and this
value is also referenced by the Settings class generated by VS.NET, you can
find the following code in the "settings.designer.cs" file:

===============
[global::System.Configuration.ApplicationScopedSett ingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttr ibute()]

[global::System.Configuration.SpecialSettingAttribu te(global::System.Configu
ration.SpecialSetting.ConnectionString)]

[global::System.Configuration.DefaultSettingValueAt tribute("Provider=Microso
ft.Jet.OLEDB.4.0;Data Source=D:\\temp\\database_temp\\aspdb.mdb")]
public string AccessDBConnectionString {
get {
return ((string)(this["AccessDBConnectionString"]));
}
}
==============================

So it actually will read the value from app.config file first, and if not
exists, use the default value(set by the
DefaultSettingValueAttribute(....)).

thus, when you reference the class library and use the TableAdaper in a
upstream application(asp.net or winform or console) and want to modify the
connectionstring used by the TableAdapter, you should override the above
connectionstring setting in the application's configuration file. For
example, the following fragment override the connectionstring (refer to the
mdb file in App_Data dir) in the ASP.NET application's web.config file:

============================
<add name="URLSiteLib.Properties.Settings.AccessDBConne ctionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=|DataDirectory|aspdb.mdb"
providerName="System.Data.OleDb" />
==============================

Hope this helps clarify it a little. If you have anything unclear or any
further question this on this, please feel free to let me know.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

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

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 13 '06 #2
You’re absolutely spot on Steven.

I will try over riding the connection string as you explain.

Thanks for your reply.
--
Regards

Martyn Fewtrell
"Steven Cheng[MSFT]" wrote:
Hello Martyn,

From your description, the problem you met here is the
TypedDataSet/TableAdapter(defined in a separate class library project)
which connect to an Access mdb file will not quite work when referenced in
ASP.NET web application since the TableAdapter will still refer to the
original database connectionstring(file path) to mdb file used at
design-time, correct?

I think what you do here is correct and it is certainly reasonable to
separate the TypedDataSet/TableAdapter(or other custom data access/business
component) into separate class library when we want to provide good
encapsulation and isolation of differnt Tier in our application. The reason
why the TableAdapter will reference the connectionstring(file path) at
design-time is because VS IDE will help generate a setting class which
contains a dictionary of data, and the TableAdapter's connectionstring is
also stored in it. However, this value is overridable if we use the class
library in other upstream application layer(in asp.net or winform
application), this can be done through override the connectionString in the
upstream application's application config file(web.config for asp.net
application). Actually, in the class library project, you will find an
"app.config" file also, and it will contains the connectionstring entry for
the TableAdapter, e.g.

===================
<add name="URLSiteLib.Properties.Settings.AccessDBConne ctionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=D:\temp\database_temp\aspdb.mdb"
providerName="System.Data.OleDb" />
===================

this is the one you set when creating the DataSet/Tableadapter, and this
value is also referenced by the Settings class generated by VS.NET, you can
find the following code in the "settings.designer.cs" file:

===============
[global::System.Configuration.ApplicationScopedSett ingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttr ibute()]

[global::System.Configuration.SpecialSettingAttribu te(global::System.Configu
ration.SpecialSetting.ConnectionString)]

[global::System.Configuration.DefaultSettingValueAt tribute("Provider=Microso
ft.Jet.OLEDB.4.0;Data Source=D:\\temp\\database_temp\\aspdb.mdb")]
public string AccessDBConnectionString {
get {
return ((string)(this["AccessDBConnectionString"]));
}
}
==============================

So it actually will read the value from app.config file first, and if not
exists, use the default value(set by the
DefaultSettingValueAttribute(....)).

thus, when you reference the class library and use the TableAdaper in a
upstream application(asp.net or winform or console) and want to modify the
connectionstring used by the TableAdapter, you should override the above
connectionstring setting in the application's configuration file. For
example, the following fragment override the connectionstring (refer to the
mdb file in App_Data dir) in the ASP.NET application's web.config file:

============================
<add name="URLSiteLib.Properties.Settings.AccessDBConne ctionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=|DataDirectory|aspdb.mdb"
providerName="System.Data.OleDb" />
==============================

Hope this helps clarify it a little. If you have anything unclear or any
further question this on this, please feel free to let me know.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

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

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 13 '06 #3
Thanks for the reply Martyn,

Glad that the information is of assistance. If you have any further
questions or anything unclear, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 13 '06 #4

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

Similar topics

21
by: Chris | last post by:
I'm trying to get an existing VS.NET project up on my Win2003 server and I get the following error (on the actual website page): "It is an error to use a section registered as...
3
by: Christopher Kimbell | last post by:
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...
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: Islamegy® | last post by:
I was using WebService and i want to convert this WebService to Class Library so I Removed Inhertance and Attributes with no problems. But When i try to import Exist Dataset or TableAdapters i...
1
by: Suhas Vengilat | last post by:
Hi, I have a class library project, where I have created a TableAdapter with a table from SQL Server database. When I reference this library in another classlibrary project, i am not able to use...
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...
19
by: cpnet | last post by:
I'm using VS2005, C#, ASP.NET 2.0. I'm trying to create a report using SQL Reporting Services (to be used in local mode so I don't have to deal with SQL Server). When I create a new report in my...
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
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...
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...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.