none
Unable to get razor page working RRS feed

  • Question

  • Still unable to make a simple razor webpage with visual studio 2019.

    Step 1: Clicked on "make Asp.NET core web app". 2 minutes, nice demo page pops up. 

    Step 2: Adding www hosted and existing Sql Server db to WEBSITE (not to VS, can see it there, credentials tested in SSMS) -> Other tools: 2 minutes, visual studio: 100+ hours and still fail! 

    Need to use existing sql server db, need to use own sql, not datagrids. Please help me how to get this done!


    Sunday, December 1, 2019 10:38 PM

Answers

  • Have you included sql server namespace ?

    using System.Data.SqlClient;


    n.Wright

    • Marked as answer by Jonas100 Friday, January 17, 2020 10:03 AM
    Thursday, January 2, 2020 8:39 PM

All replies

  • I think it's called SQL Server Studio.

    George Frias - AWWshop, Wiki1978

    Sunday, December 1, 2019 10:56 PM
  • Hi Jonas100,

    Welcome to MSDN forum.

    Did visual studio throw some exceptions? If so, could you please share them here, which will help us analysis it better. And if possible, we will appreciate that you could share a simple sample to help us to reproduce this issue.

    In addition, you could follow this video to reconfigure your Sql connection for your razor page.

    Look forward to your reply.

    Best Regards,

    Dylan

    Note: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you. 

    Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Monday, December 2, 2019 3:31 AM
  • Hi Jonas100,

    Sorry to disturb you.

    According to your description, do you mean you’d like to use own sql in your project? And as far as I know, Razor Page uses EFCore by default and doesn’t use ADO .NET.

    Maybe, you could use ADO .NET to run SQL.

    Hope this could help you.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 3, 2019 6:25 AM
  • Hi & thank for the answers. 

    Simple workaround: credentials, connection, sql statements, c# => all in the @{} area.

    But: this is not at all what visual studio was designed for.

    Installed sqlite but still nothing is working.

    Re-Asking my question:

    We have: vs 2019 with sample page & user authentication.
    We have: sql db with lots of content.
    How can i set up and bring the data the webpage with data sourced from an existing, already running sql web db (no azure db, no local db).

    Hope you are still patiently with me.


    Thursday, December 12, 2019 3:19 PM
  • Hi Jonas100,

    Thank you for feedback.

    As far as I know, we need to use System.Data.SqlClient namespace to build a connection with sql server database in C# application. 

    We recommend you could follow this video to connect Sql server in C# web application.

    Hope it could help you.

    Best Regards,

    Dylan 


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, December 13, 2019 10:26 AM
  • Thank you for your efforts and sending the link. Sorry, but its not working at all. 

    VS is throwing tons of Errors and complainning about whatever-seems-not-to-be-there or not found. VS simply sucks as hell!

    Spent another countless hours on VS including the complete series of hanselmann videos. VS is all wierd and ultra-"complificated" for no reason. I simply hate it. 

    15 years on sql, webmatrix and other toolboxes like react or php builder. Never saw anything so ridiculuosly complexified as trying to make a website with asp core on VS. 

    Where is the new Webmatrix? Where is a simple Webbuilder instead of a "You-may-do-a-trillion-things-in-a-quadrillion-possilbe-ways-but-nothing-is-working" Tool?


    Maybe it has someting to with the community edition?

    Does anybody in fact devevelop REAL WORLD (not hello world websites) websites with data access on VS community edition?

    Tuesday, December 31, 2019 3:00 PM
  • little bit more precise:

    Datareader: not found or not working

    Request.Something example RawUrl OR Url OR anything else in Servervariables: not found or not working or not avialable or whatever else

    New Sample page not more available yet...

    Pffff.....

    Tuesday, December 31, 2019 4:23 PM
  • Have you included sql server namespace ?

    using System.Data.SqlClient;


    n.Wright

    • Marked as answer by Jonas100 Friday, January 17, 2020 10:03 AM
    Thursday, January 2, 2020 8:39 PM
  • Fine! Data Client back and working since VS is completely reinstalled.

    Had "ASP.NET Razor 3.2.7" instead of "ASP.NET CORE Razor 3.something" which obviously caused tons of error statements and misbehaviour.
    The machine seems not to really understand if you are on "ASP.NET" or on "ASP.NET CORE".
    The machine seems not to really understand if you are on Razor Web or on MVC Web.

    Maybe I am just too stupid to use VS. So, loading a wrong extension/s from the nuget slot machine was not a good idea.

    Pls Bill, give me some buttons to tell VS on which system we are, including extension-compatibility check. Or simply relaunch Webmatrix ;-).

    Sorry for niggling so much and a happy new year to anyone.

    Friday, January 3, 2020 12:38 PM
  • endless story...

    System.InvalidOperationException: Unsupported handler method return type 'System.String'. at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.CreateHandlerMethod(HandlerMethodDescriptor handlerDescriptor) at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.CreateExecutor(HandlerMethodDescriptor handlerDescriptor) at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvokerProvider.GetHandlerExecutors(CompiledPageActionDescriptor actionDescriptor) at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvokerProvider.CreateCacheEntry(ActionInvokerProviderContext context, FilterItem[] cachedFilters) at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvokerProvider.OnProvidersExecuting(ActionInvokerProviderContext context) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionInvokerFactory.CreateInvoker(ActionContext actionContext) at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointFactory.<>c__DisplayClass7_0.<CreateRequestDelegate>b__0(HttpContext context) at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext) --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

    Friday, January 3, 2020 1:23 PM
  • SQL server on VS is quite a complex task.

    1/ Create a database. I use SQL server management studio. Means learning SSMS.

    2/ Write code to interface between SQL server and your code.

    Using entity framework is now popular as its easier to use than direct sql server commands.

    Look online for sql server database code examples to build on.

    A typical string for interfacing to sql server is:

            string openstring = @"Server = mssqluk5.prosql.net; User ID=nigelwright7557; Password= ********;" +
                " connect timeout=30;User Instance = false; TrustServerCertificate = True; Trusted_Connection=True;" +
                "Encrypt = True;Integrated Security = False;database=Database1; ";
     


    n.Wright

    Thursday, January 9, 2020 8:32 AM
  • Thanks for your hints, 

    to connect a hosted db via SSMS is fifteen seconds, i'm on ssms since 10 years. 

    Finally data driven page was working with a connection to hosted live db without ef.


    Suddenly VS tells me that "Up is already a member of something in Data/Migration/..." and IndexModel is already defined in my namespace. Useless to say that i never told VS to build a new SQL dependency member and a new IndexModel ! And more news: VS told me today, that Razor web "UI" component is not found - i sware it was working already! What the hell ...

    So page is crashed now and two weeks of work. Begin again from the scratch. 


    Errors:

    [assembly: Microsoft.AspNetCore.Identity.UI.UIFrameworkAttribute("Bootstrap4")]

    CS0101 Der Namespace "XXX.Pages.mainz" already contains a definition for "IndexModel". ...
    Type "IndexModel" defines already Member namens "OnGet" mit den gleichen Parametertypen.

    CS0234 Der Typ- oder Namespacename "UI" ist im Namespace "Microsoft.AspNetCore.Identity" nicht vorhanden. (Möglicherweise fehlt ein Assemblyverweis.)

    UI is not there - it is gone !!!

    And finally: 

    Das Paket "Microsoft.VisualStudio.Web.CodeGeneration.Design 3.1.0" wurde nicht mit dem Projektzielframework ".NETCoreApp,Version=v3.0", sondern mit ".NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8" wiederhergestellt. Dieses Paket ist mit Ihrem Projekt möglicherweise nicht vollständig kompatibel. => This Package may not be fully compatible with to your project.


    Thursday, January 16, 2020 4:52 PM
  • Ok. Let's close this entry, it is not more "Visual studio general". Thanks to everybody.
    Friday, January 17, 2020 10:03 AM