Problems putting database layer in class library. Please help!

D

drawing in aspnet

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top