BLAZOR WEBASSEMPLY 和 MYSQL WORKBRENCH - DbContext 问题

问题描述 投票:0回答:1

我正在使用 Mysql Workbench 连接我们的服务器,如何在 Blazor 中使用它?这是什么错误?

Win32Exception:参数不正确。

SqlException:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供程序:SNI_PN11,错误:25 - 连接字符串无效)

AppDbContext.cs


using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AselWebAppV3.Shared.Models;

namespace AselWebAppV3.Server
{
    public class AppDbContext : DbContext
    {
        public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
        {

        }

        public DbSet<Defect> defects { get; set; }

      
    }
}

启动.CS

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Linq;

namespace AselWebAppV3.Server
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit       https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<AppDbContext>(options => options.UseSqlServer("Server=10.111.*.****,3307; uid=sa; Password=*******; Database=****; Integrated Security=True;"));
            services.AddControllersWithViews();
            services.AddRazorPages();
           
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebAssemblyDebugging();
            }
            else
            {
                app.U

seExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapFallbackToFile("index.html");
            });
        }
    }
}

尝试连接服务器`

mysql blazor mysql-workbench dbcontext
1个回答
0
投票

尝试将

trustservercertificate=true
添加到您的连接字符串,因为错误显示 trustServercert

"ConnectionStrings": {
    "Connection": "Server=localhost;User Id=admin;Password=****;Database=****;
    Trusted_Connection=True;
    TrustServerCertificate=True;"  
},
© www.soinside.com 2019 - 2024. All rights reserved.