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 } }
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;
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:
The userConn is the name of the connection string defined in web.config
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:
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
Ok, I will try it, thank you very much, I'll tell you if it worked or not.
Thank you, Bruno Mexia
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..
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!
is working on a reply...