What I am trying to do: Use the ASP.NET Dynamic Data web template with an SQL Server 2008 database.
The procedure I have used: 1. File>New>Website
2. Choose the ASP.NET Dynamic Data Entities website template
3. Right Click the AppData folder
4. Choose: Add Existing Item
5. Navigate to the .mdf file of my database
6. Click on the Add button.
The following Visual Studio error message appears: "The file cannot be opened because it is being used by another process.
Please close all applications that might access this file and try again"
What I have done to try to resolve the problem: 1. Shut down all applications
2. Restart my machine (Win 7 pro)
3. Repeat the six steps in the foregoing procedure
The result: Visual Studio still gives the same error message.
My Questions: 1. What program mght be running to cause this behaviour & how to I find it?
2. Is this a bug?
The following Visual Studio error message appears: "The file cannot be opened because it is being used by another process.
Please close all applications that might access this file and try again"
Hi Ken, this is because you are trying to add your DB to the projecxt (i.e. copy it there) not connect to it, to connect add a Entity Framework data model and then select your Data base and all should go well.
If you actually want to have the DB in the App_Data folder then you will need:
To have SQL Express installed localy and on your web server.
Temporarily stop your SQL Server so that the DB is accessable then copy it to the App_Data foilder.
Dynamic Data
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Ok Steve,
I figured out the next step.
I just right clicked the project name and chose "Add New Item > ADO.NET Entity Data Model"
A short while later, I saw the edmx file and the classes appeared in the VS 2010 document window.
Now I'm trying to understand the complicated comments in the global.asax file to figure out how to register my data model with Dynamic Data and enable scaffolding...
I have been floundering around trying to figure out what use for a data context.
Let's say my database is called "myDB_00" (in the server explorer it shows as ~\sql2008a.myDB_00.dbo).
The Global.asax file notes say that I should use a line such as:
DefaultModel.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = true });
What I'm trying to figure out is what should replace "YourDataContextType" in this line.
I tried "myDB_00DMDataContext" but the IDE underlines this in red and tells me that:
"the type or namespace name "myDB_00DMDataContext" could not be found(are you missing using directive or assembly reference?)"
The name of the data context is the name of your EF (Entity Framework) model and the name space, for instance I usually put my data models in a Models folder and there for my model namespace is usualy Models so in my project it would be:
Models.myDB_00Model
You will see the name in the bottom of the wizard when yoiu create it.
Dynamic Data 4
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
The first one has helped me to solve some immediate problems and I have managed to get the Default.aspx to run. What helped most was seeing the action on the screen.
In contrast, the voice over is full of unnecessary chatter and "er's" that detract from the effectiveness of the delivery.
Anyway, I can now see all the tables on the home page but when I click on any of the tables I get the error:
Unable to cast object of type 'myDB_00DMDataContext' to type 'System.Data.Objects.ObjectContext'.
Member
37 Points
168 Posts
Dynamic Data problem - VS 2010 Pro
Dec 05, 2010 01:47 PM|farm boy|LINK
What I am trying to do:
Use the ASP.NET Dynamic Data web template with an SQL Server 2008 database.
The procedure I have used:
1. File>New>Website
2. Choose the ASP.NET Dynamic Data Entities website template
3. Right Click the AppData folder
4. Choose: Add Existing Item
5. Navigate to the .mdf file of my database
6. Click on the Add button.
The following Visual Studio error message appears:
"The file cannot be opened because it is being used by another process.
Please close all applications that might access this file and try again"
What I have done to try to resolve the problem:
1. Shut down all applications
2. Restart my machine (Win 7 pro)
3. Repeat the six steps in the foregoing procedure
The result:
Visual Studio still gives the same error message.
My Questions:
1. What program mght be running to cause this behaviour & how to I find it?
2. Is this a bug?
Thanks
Ken
Dynamic data problem
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data problem - VS 2010 Pro
Dec 05, 2010 03:14 PM|sjnaughton|LINK
Hi Ken, this is because you are trying to add your DB to the projecxt (i.e. copy it there) not connect to it, to connect add a Entity Framework data model and then select your Data base and all should go well.
If you actually want to have the DB in the App_Data folder then you will need:
Dynamic Data
Always seeking an elegant solution.
Member
37 Points
168 Posts
Re: Dynamic Data problem - VS 2010 Pro
Dec 05, 2010 04:18 PM|farm boy|LINK
Hi Steve,
Thanks for that.
However, I don't want to use SQL Express.
I want to use my SQL Server 2008 database.
Right now I'm using SQL Server 2008 SP2.
Later I will use SQL Server 2008 R2.
Any idea how I can get it running from a full database?
Thanks
Ken
Member
37 Points
168 Posts
Re: Dynamic Data problem - VS 2010 Pro
Dec 05, 2010 04:39 PM|farm boy|LINK
Steve,
Please can you be more explicit about what steps you are suggesting when you say:
1: Add a "Entity Framework data model" How?
2: Select your database. How?
What I have now done is to establish a connection to my database in database explorer.
Not sure where to go from here.
Can you please give me some pointers?
Thanks
Ken
Member
37 Points
168 Posts
Re: Dynamic Data problem - VS 2010 Pro
Dec 05, 2010 04:52 PM|farm boy|LINK
Steve,
I have now established a connection to my database using Server Explorer and I can access all the tables etc.
What I'm not sure about is what you mean by "add a Entity Framework data model"
Didn't I do this in steps 1 & 2?
Or do you mean something else?
Now that the database connection is established in Server Explorer, what else do I need to use the dynamic data service?
Thanks
Ken
Member
37 Points
168 Posts
Re: Dynamic Data problem - VS 2010 Pro
Dec 05, 2010 05:37 PM|farm boy|LINK
Ok Steve,
I figured out the next step.
I just right clicked the project name and chose "Add New Item > ADO.NET Entity Data Model"
A short while later, I saw the edmx file and the classes appeared in the VS 2010 document window.
Now I'm trying to understand the complicated comments in the global.asax file to figure out how to register my data model with Dynamic Data and enable scaffolding...
Thanks for the pointers.
Ken
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data problem - VS 2010 Pro
Dec 05, 2010 06:13 PM|sjnaughton|LINK
Sorry I didn't get back to you I was out, are you sorted now?
Dynamic Data 4
Always seeking an elegant solution.
Member
37 Points
168 Posts
Re: Dynamic Data problem - VS 2010 Pro
Dec 05, 2010 06:28 PM|farm boy|LINK
Well, not quite.
I have been floundering around trying to figure out what use for a data context.
Let's say my database is called "myDB_00" (in the server explorer it shows as ~\sql2008a.myDB_00.dbo).
The Global.asax file notes say that I should use a line such as:
What I'm trying to figure out is what should replace "YourDataContextType" in this line.
I tried "myDB_00DMDataContext" but the IDE underlines this in red and tells me that:
"the type or namespace name "myDB_00DMDataContext" could not be found(are you missing using directive or assembly reference?)"
Any suggestions?
Thanks
Ken
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data problem - VS 2010 Pro
Dec 06, 2010 04:59 AM|sjnaughton|LINK
Have you tried watching this Getting Started with Dynamic Data there are more videos here http://www.asp.net/web-forms/data under the section Dynamic Data.
The name of the data context is the name of your EF (Entity Framework) model and the name space, for instance I usually put my data models in a Models folder and there for my model namespace is usualy Models so in my project it would be:
Models.myDB_00Model
You will see the name in the bottom of the wizard when yoiu create it.
Dynamic Data 4
Always seeking an elegant solution.
Member
37 Points
168 Posts
Re: Dynamic Data problem - VS 2010 Pro
Dec 06, 2010 03:33 PM|farm boy|LINK
Thanks for the tip about the videos.
The first one has helped me to solve some immediate problems and I have managed to get the Default.aspx to run. What helped most was seeing the action on the screen.
In contrast, the voice over is full of unnecessary chatter and "er's" that detract from the effectiveness of the delivery.
Anyway, I can now see all the tables on the home page but when I click on any of the tables I get the error:
Unable to cast object of type 'myDB_00DMDataContext' to type 'System.Data.Objects.ObjectContext'.
So I'm now on another treasure hunt!
Ken
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data problem - VS 2010 Pro
Dec 06, 2010 04:08 PM|sjnaughton|LINK
Hi Ken, I woudl try a simple site using Northwind database and follow the video, that's how I started I folled a few videos and blog [:)]
Dynamic Data 4
Always seeking an elegant solution.
Member
37 Points
168 Posts
Re: Dynamic Data problem - VS 2010 Pro
Dec 07, 2010 06:00 PM|farm boy|LINK
Hi Steve,
I have solved the problems and got the first site running.
Thanks for your help along the way.
Ken
All-Star
17916 Points
5681 Posts
MVP
Re: Dynamic Data problem - VS 2010 Pro
Dec 08, 2010 08:27 AM|sjnaughton|LINK
Your welcome Ken
Dynamic Data 4
Always seeking an elegant solution.