Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, June 15, 2012 3:05 PM
When I run try testing my movies database, I get the following error.
When I type line 5 "Database" does not show as an option, so I suspect a library is missing, but I don't know for certain.
**Compiler Error Message: **CS0103: The name 'Database' does not exist in the current context
Source Error:
|
All replies (13)
Sunday, June 24, 2012 2:14 PM âś…Answered
This works. Thank you.
I managed to find a copy of WebMatrix.Data.dll on my laptop, copied this into the bin sub-directory of my project. I then added
@using WebMatrix.Data to the start of the cshtml file, and the database search now works.
i.e.
@using WebMatrix.Data;
@{
var db = Database.Open("Movies");
var sqlQ = "SELECT * FROM Favorites";
var data = db.Query(sqlQ);
}
Friday, June 15, 2012 3:20 PM
In my classes that use database, I have this lines in the beggining of code.
using System;
using System.Collections.Generic;
using System.Web;
Friday, June 15, 2012 4:02 PM
Are you using Visual Web Developer or Visual Studio? If so, add
@using WebMatrix.Data;
to the top of the file
Friday, June 15, 2012 4:38 PM
I am using WebMatrix and the file is a cshtml.
The new message is:
"The type or namespace name 'WebMatrix' could not be found"
Friday, June 15, 2012 5:22 PM
I am using WebMatrix
Which version?
Sunday, June 17, 2012 6:20 PM
I'm having the same problem, and I'm using Microsoft Webmatrix 2. The Web Development 101 tutorial is based off of Webmatrix1, I believe.
Friday, June 22, 2012 5:10 PM
I'm having the same problem.
Also using WebMatrix following the Movies tutorial.
My issue is it is looking for the database in "...Documents..." but the database is in "MyDocuments", and it cannot resolve that difference.
This is in Windows 7 (64).
Saturday, June 23, 2012 3:52 AM
You should try reinstalling WebMatrix
Saturday, June 23, 2012 8:09 AM
I also have this issue, tried installing WebMatrix 2 on another PC and still getting the error.
I have had a look on the net, and it could be that the webmatrix.data.dll isn't being installed. I have done a search on both PC's, and can't find a copy of this dll.
Saturday, June 23, 2012 3:10 PM
I managed to find a copy of WebMatrix.Data.dll on my laptop, copied this into the bin sub-directory of my project. I then added
@using WebMatrix.Data to the start of the cshtml file, and the database search now works.
i.e.
@using WebMatrix.Data;
@{
var db = Database.Open("Movies");
var sqlQ = "SELECT * FROM Favorites";
var data = db.Query(sqlQ);
}
Tuesday, June 26, 2012 8:21 AM
This is tutorial shows you how to add database connectivity in WebMatrix 2 - http://www.asp.net/web-pages/tutorials/introducing-aspnet-web-pages-2/displaying-data
Tuesday, November 6, 2012 11:09 PM
I tried to include "@using WebMatrix.Data;" as the first statement of _PageStart.cshtml, so that I don't have to include it for all pages of the folder. But it failed. Why??? Where can I specify "@using WebMatrix.Data;" only once for all pages?
Wednesday, November 7, 2012 8:04 AM
I think that you have two options:
- include the using directive in any page;
- copy the dll into the bin folder of your site.
About this, all the templates of the Webmatrix 2.0 RTM release have the WebMatrix.Data.dll in their bin folder and there is no need to insert the using WebMatrix.Data directive into the code.
Instead, if you are using the Empty Site template of WebMatrix 2 beta, you should follow the instructions at the "Error in Database Connection" chapter of this tutorial or upgrade your WebMatrix installation.
Anyway, if you have problems, open a new thread and don't use a thread opened by another user.