Copied to clipboard

Flag this post as spam?

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


  • Bruno 12 posts 32 karma points
    Apr 17, 2014 @ 02:51
    Bruno
    0

    Can't connect to Database

    I can't connect to my database bacause it gives me an error: The name 'Database' does not exist in the current context

    Anyone? This is really urgent. 

    When I call this method:

    var db = Database.Open("userConn");

    The userConn is the name of the connection string defined in web.config

     

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
    var db = Database.Open("userConn");
    var data = db.Query("SELECT * FROM Users");

    foreach (var row in data){

    @row.name
    @row.address
    @row.address2
    @row.field

    }
    }
  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Apr 17, 2014 @ 12:08
    Jeroen Breuer
    0

    You get this error because the Database object doesn't exist. Try to replace it with: Umbraco.Core.ApplicationContext.Current.DatabaseContext.Database. So for example:

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

    I see that your code inherits from DynamicNodeContext. That is the old legacy Razor and it's recommended to use partial view macro files. More info here: http://our.umbraco.org/forum/developers/razor/44664-Confused-over-when-DynamicNodeList-is-returned?p=0#comment160691

    Jeroen 

  • Bruno 12 posts 32 karma points
    Apr 17, 2014 @ 12:11
    Bruno
    0

    Ok, I will try it, thank you very much, I'll tell you if it worked or not.

    Thank you, Bruno Mexia

  • Bruno 12 posts 32 karma points
    Apr 17, 2014 @ 22:08
    Bruno
    0

    I can't seem to make it work, would you be able to help me via TeamViewer or something? 

    It's the last thing I need now to complete this project but can't seem to make it work..

  • Bruno 12 posts 32 karma points
    Apr 18, 2014 @ 01:22
    Bruno
    0

    I fixed it, I needed the WebMatrix.Data.dll, which I didn't have, after that I did @using WebMatrix.Data

    It is working now, thank you! 

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies