Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alex 79 posts 416 karma points
    Jan 28, 2016 @ 11:35
    Alex
    0

    DataBase Connection

    Hi

    I have trying to simple display data from the Umbraco database, using only Razor But It gives error?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{ 
        var DB = Database.Open("umbracoDbDSN"); 
        var DataTypes = DB.Query("SELECT * FROM cmsDataType");
    }
    
    @{
        foreach (var item in DataTypes)
        {  
            @item
        }
    }
    

    Using this code

  • Alex 79 posts 416 karma points
    Jan 28, 2016 @ 11:36
    Alex
    0

    Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

  • Samira 113 posts 452 karma points
    Jan 28, 2016 @ 11:40
    Samira
    100

    Hi

    Try this

    var db = Umbraco.Core.ApplicationContext.Current.DatabaseContext.Database;
    

    hope this help

  • Alex 79 posts 416 karma points
    Jan 28, 2016 @ 11:43
    Alex
    0

    It now complains about the Open statement and did not work

  • Nik 1599 posts 7179 karma points MVP 6x c-trib
    Jan 28, 2016 @ 13:00
    Nik
    0

    And what happens when you take the Open line out of your code?

Please Sign in or register to post replies

Write your reply to:

Draft