System.Invalidoperationexception Database Opening Error?

Asked

Viewed 45 times

2

I am using webMatrix, to develop an example in Jquerymobile, I am having the following error

@{
    Layout="~/shared/_Layout.cshtml";
    Page.Title = "Home";
    Page.Header = "Categorias";
    var db  = Database.Open("Northwind40.sdf");
    var sql = @"SELECT [CATEGORY ID] AS ID, [CATEGORY NAME] AS NAME FROM CATEGORIES 
    ORDER BY [CATEGORY NAME]";
    var data = db.Query(sql);
}


<div data-role="content">

    <ul data-role="listview" data-inset="true" data-theme="d">

          @foreach(var item in data){
            <li><a href="/Category/@item.ID">@item.NAME</a></li>
          }

    </ul>

</div>

Error message:

  Connection string "Northwind40.sdf" was not found.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.InvalidOperationException: Connection string "Northwind40.sdf" was not found.

    Source Error: 

    Line 3:      Page.Title = "Home";
    Line 4:      Page.Header = "Categorias";
    Line 5:      var db  = Database.Open("Northwind40.sdf");
    Line 6:      var sql = @"SELECT [CATEGORY ID] AS ID, [CATEGORY NAME] AS NAME FROM CATEGORIES 
    Line 7:      ORDER BY [CATEGORY NAME]";

1 answer

0


Substitute:

var db  = Database.Open("Northwind40.sdf");

For:

var db  = Database.Open("UmaConnectionStringVálida");

I don’t know what database technology that object Database uses, but possibly this file .sdf nor exists in your example.

  • Thanks, the error was fixed like this : var db = database.user ("Northwind40");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.