Problems putting database layer in class library. Please help!

Tech-Archive recommends: Fix windows errors by optimizing your registry



Question about putting the data layer in a separate class library.

I keep reading that the data layer should be separated from the
presentation layer and put in its own class library. I am trying to
do this but running into a problem. I'm hoping someone can point me
in the right direction. I first create a class library (all code in
C#) and within this class library create a very simple Sql Server
Express database (.mdb) file. It's columns are [index] and miles with
index being the key value. I then generate a dataset by picking Add
New Item->DataSet. I drag my one table onto the dataset designer and
end up with a file called SimpleRunningDataSetDesigner.cs that has
(among other things) the following:

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Fill,
true)]
public virtual int Fill(SimpleRunningDataSet.SimpleRunningDataTable
dataTable) {
this.Adapter.SelectCommand = this.CommandCollection[0];
if ((this.ClearBeforeFill == true)) {
dataTable.Clear();
}
int returnValue = this.Adapter.Fill(dataTable);
return returnValue;
}

Of course, there is much more code and I'd be happy to post any/all of
it. Anyhow, based on previous work where I had only 1 layer, this
looked promising.

I compiled the class library and then created a web application (file
based system). I added the class library as a reference and put an
objectdatasource on the main form. I chose the only dataadapter
available:
DataLayer.SimpleRunningDataSetTableAdapters.SimpleRunningTableAdapter

I put a GridView on the page and used the objectdatasource mentioned
above.
But when I run the web page, I get the following error:
An attempt to attach an auto-named database for file C:\Documents and
Settings\Andrew\My Documents\Visual Studio 2005\WebSites
\SimpleThreeTieredArchitecture\WebApp\App_Data\App_Data\VerySimple.mdf
failed. A database with the same name exists, or specified file cannot
be opened, or it is located on UNC share.

Has anyone seen this before?

To verify the problem has something to do with using a separate class
library I copied the .mdb file to a brand new web app project and
created a dataset within that web app project using the copied .mdb
file. I again used an objectdatasource and gridview as above. When I
do everything in one webapp project I have no problem and the page
displays.

A couple of possibly relevant points: I notice that in the class
library when I create the dataset I get an .xsd file. However, it
appears to be just a design page and not an .xsd code page like you
get when you do the same exercise in the web app. Also, I get files
under the .xsd file called SimpleRunningDataSet.cs, *.Designer.cs,
*.xsc, and *.xss. When I do this exercise in the web app project, I
only get the .xsd file (design and code) and a .xss file. Also, I'm
not using IIS. I pick 'file system'for the web apps.

Can anyone point me to an article, book or tutorial explaining this
behavior? I'm sure it's something simple I need to fix but I've been
knocking my head against a wall for some time on this one. I have
seen mention of the error message above in the newsgroups but no
solution. My research leads me to suspect that it might be some sort
of permissions problem. Perhaps the WebApp does not have permission
to read the database that's in the class library layer? I did try
changing the permissions of every folder in sight to include the user
ASPNET. No luck. I also saw suggestions that the connectionString in
the class library might be wrong. To this end I changed it from:
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|
DataDirectory|\App_Data\VerySimple.mdf;Integrated
Security=True;Connect Timeout=30;User Instance=True"

to

C:\Documents and Settings\Andrew\My Documents\Visual Studio
2005\WebSites\SimpleThreeTieredArchitecture\DataLayer\App_Data
\VerySimple.mdf

It made no difference.

If you've read this far, many thanks. Again, any comments, ideas,
flames, or suggestions for more appropriate newsgroups would be most
welcome. Eventually, I'd like to use the built in ASP.NET security
model (ASPNET.mdb) to check username, passwords, roles, etc. I've
already done this when everything is in one big webapp project, but I
suspect there will be problems putting that in the class library too!

Thanks,
Dave.

.



Relevant Pages

  • Re: some basic dotnet questions
    ... My web app needs for arcade machine vendors to count machines and use the ... now they want web based and local windows based app to do this. ... Database layer- In my case I guess this is sql server 2000 itself?? ... Data layer - is this the actual tables and data, ...
    (microsoft.public.dotnet.general)
  • Re: Help! How many layers in my app?
    ... layer = something logical separated but still has to run on ... So you have either a 3 tier web app: ... data access layer = .cs with some database interface a la DAAB ...
    (microsoft.public.dotnet.languages.csharp)
  • what files in what directoris will I need to make a web app with v
    ... My web app needs for arcade machine vendors to count machines and use the ... Data layer - is this the actual tables and data, ... business layer - business logic such as totalling the machine and figuring ... Adam S ...
    (microsoft.public.dotnet.general)
  • Presentation layer depends on ????
    ... I have a ASP.NET 2.0 Web app which has 3 layers ... Presentation layer which contains UI elements and Input validation ... I understand that each layer is a independent entity and can be ... layer depend on the Business layer only or does it depend on the ...
    (microsoft.public.dotnet.framework.aspnet)