Question

I'm programming a Razor website from the Ground up using VS 2013. I started with a blank Web Application Project and slowly added files and functionality to suit what I need. Basically its just jquery ui, css, and a few basic test webpages.

Keep in mind, I have added a reference to: WebMatrix.Data.dll

Now when I try to connect to my database, I use the following code:

@{
Layout = @"~\_SiteLayout.cshtml";
Page.Title = "Main Tabs";
var DB = Database.Open("NASDB");
var QString = "SELECT * from Tabpage";
}

But this code doesn't work. It says "Database does not exist in this context."

But when I use this code everything works:

@{
Layout = @"~\_SiteLayout.cshtml";
Page.Title = "Main Tabs";
var DB = WebMatrix.Data.Database.Open("NASDB");
var QString = "SELECT * from Tabpage";
}

This is functional, but not easily readable. Is there any way to fix this? So just Database will work. I also have to have the "Copy Local" property of the "WebMatrix.Data" reference set to true. Is there any way to avoid this as well?

Was it helpful?

Solution

At The top of the page:

@using Webmatrix.Data

or you can add a reference in the webconfig file that exists in your views folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top