Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Blazor app and 'local' DataPortal #924

Open
Chicagoan2016 opened this issue Apr 10, 2020 · 3 comments
Open

Blazor app and 'local' DataPortal #924

Chicagoan2016 opened this issue Apr 10, 2020 · 3 comments

Comments

@Chicagoan2016
Copy link

Question
This may be a very simple question : ) but how do we connect to a on-premise sql instance? I am used to using connection strings from configuration files. We are also going to use the default 'local' data portal so no application server.
Kind Regards

Version and Platform
CSLA version: 5.xx
OS: Windows
Platform: Blazor

@BlagoCuljak
Copy link

I'm not sure what's the difference between local Dataportal in the one in the cloud. Both of them connect to SQL DB (local or cloud) using some config files.

If you are using EntityFramework for ORM and want to connect to your DB using appsettings.json then your need to change:

  1. In EF Dbcontext
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            IConfigurationRoot configuration = new ConfigurationBuilder()
            .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
            .AddJsonFile("appsettings.json")
            .Build();
            optionsBuilder.UseSqlServer(configuration.GetConnectionString("connstring"));
        }
  1. In Dataportal, Startup.cs in "public void ConfigureServices(IServiceCollection services)"
services.AddDbContext<Dbcontext>(options =>
       options.UseSqlServer(Configuration.GetConnectionString("connstring"), 
       sqlServerOptions => sqlServerOptions.CommandTimeout(600)));
  1. Add appsettings.json, add the connection:
{
  "ConnectionStrings": {
    "connstring": "Server=192.168.1.1;Initial Catalog=DataBaseName;Persist Security Info=False;User ID=sa;Password=ChangeMyPassword;MultipleActiveResultSets=False;"
  }

@Chicagoan2016
Copy link
Author

@BlagoCuljak thanks

@rockfordlhotka
Copy link
Member

Client-side Blazor does not have any way to talk directly to a database. afaik System.Data, entity framework, etc. are not available in the browser.

@Chicagoan2016 Chicagoan2016 reopened this Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants