Copied to clipboard

Flag this post as spam?

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


  • saif 68 posts 88 karma points
    Jan 18, 2012 @ 15:57
    saif
    0

    Razor connection Error

    Hi All,

    I am newbie to Razor. I am trying to connect to database using following code but it throws an error

    Error loading MacroEngine script (file: FetchDatawithRazor_C.cshtml)

    I successfully conected with the same database using Asp.net  web user controls.

    one more thing I am not sure why try catch is not working effectively.

    any support would be lot appriciated.

    Here is the code I am using to connect with database.

    @using System.Data
    @using System.Data.SqlClient
       
        @{
        var db = Database.Open("healthyschools");
        var ermsg ="";

       try
                {
                   // var db = Database.Open("healthyschools");
                    ermsg="There is no error in code";
                }
                catch
                {
                    ermsg="Error in code! ";
                }
        }

    <html>
    <head>
    <title>Displaying Data </title>
    </head>
    <body>
    <h1>keyStages</h1>
    <div id="grid">
    @ermsg

    </div>
    </body>
    </html>

  • Rodion Novoselov 694 posts 859 karma points
    Jan 18, 2012 @ 16:08
    Rodion Novoselov
    0

    Hi. The Database class you're trrying to use is specific to WebMatrix and its assembly is not included into Umbraco distribution by default. To use it you have to install the assembly manually (WebMatrix.Data.dll) and to import its namespace either by @using directive in your cshtml or by web.config in the "system.web.webPages.razor/pages/namespaces" section.

  • saif 68 posts 88 karma points
    Jan 18, 2012 @ 16:37
    saif
    0

    Thank you Rodion,

    Please could you send me the link from where I could download the Webmatrix.data.dll

    thanks

     

  • Rodion Novoselov 694 posts 859 karma points
    Jan 18, 2012 @ 16:57
    Rodion Novoselov
    0

    I'm not sure where it can be download from directly, but if you have MVC3 (or maybe VS 2010 SP1) installed then it can be found inside somewhere like "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\".

    And also I'm not aware from which other webmatrix assemblies it can depend on - perhaps you will need to include some other assemblies from this folder as well.

  • saif 68 posts 88 karma points
    Jan 18, 2012 @ 17:13
    saif
    0

    I have installed VS 2008 and there is no chance to intall MVC3. Please could you tell me of any other way to install it.

    In case if I was able to copy from somewhere would it be compatilble with my existing system.

     

     

  • Rodion Novoselov 694 posts 859 karma points
    Jan 18, 2012 @ 17:20
    Rodion Novoselov
    0

    You can install WebMatrix itself or Visual Studio 2010 Express. Both are free and can be downloaded from Microdoft's site or installed via Web Platform Installer directly from the web. Anyway you will need to have something like that to work with Umbraco 4.7 and higher since VS 2008 doesn't work with .NET 4 and newer. 

Please Sign in or register to post replies

Write your reply to:

Draft