SQL Serverのデータベースに接続して、.netコアにWeb APIを作成しようとすると問題が発生します。.netコアSQLサーバーでの設定
これは私のコードです:
appsettings.json
{
"ConnectionStrings": {
" "DefaultConnection": "Server=ipserver,portserver;Database=Equipamiento;user id=userserver;password=password;Trusted_Connection=True;MultipleActiveResultSets=true;"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
コントローラ/ TipoEquipoMasterAPI.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
namespace VeranderAngularCore.Data
{
public class TipoEquipoMaster
{
[Key]
public int IDTipoEquipo { get; set; }
[Required]
[Display(Name ="TipoEquipo")]
public string TipoEquipo { get; set; }
[Required]
[Display(Name = "Estado")]
public int _Status { get; set; }
}
}
データ/ TipoEquipoMaster.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace VeranderAngularCore.Data
{
public class TipoEquipoContext:DbContext
{
public TipoEquipoContext(DbContextOptions<TipoEquipoContext> options) : base(options) { }
public TipoEquipoContext() { }
public DbSet<TipoEquipoMaster> TipoEquipoMaster { get; set; }
}
}
データ/ TipoEquipo/TipoEquipoMasterAPI.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using VeranderAngularCore.Data;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace VeranderAngularCore.Controllers
{
[Produces("application/json")]
[Route("api/TipoEquipoMasterAPI")]
public class TipoEquipoMasterAPI : Controller
{
private readonly TipoEquipoContext _context;
public TipoEquipoMasterAPI(TipoEquipoContext context)
{
_context = context;
}
// GET: api/values
[HttpGet]
[Route("TipoEquipo")]
public IEnumerable<TipoEquipoMaster> GetStudentMasters()
{
return _context.TipoEquipoMaster;
}
}
}
と入力しようとしてContext.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace VeranderAngularCore.Data
{
public class TipoEquipoContext:DbContext
{
public TipoEquipoContext(DbContextOptions<TipoEquipoContext> options) : base(options) { }
public TipoEquipoContext() { }
public DbSet<TipoEquipoMaster> TipoEquipoMaster { get; set; }
}
}
コントローラー:http://localhost:14621/api/TipoEquipoMasterAPI/TipoEquipo 私は次のエラーを取得する:リソースの読み込みに失敗しました:ネット:: ERR_CONNECTION_RESET
があなたの接続文字列の中に "「」余分Theresの、しかしERR_CONNECTION_RESETはコピー – Webbanditten
ネットワークの問題をほのめかすことができることを正しい試してみてください:あなたのStartup.csファイルで
は、これでservices.AddMvc()
行を置き換えますパスワード=パスワード; Trusted_Connection = True; MultipleActiveResultSets = true; –startup.csコードを投稿できますか? – Anuraj