sql接続をconfig.jsonに設定し、AuditContextクラスから使用したいとします。 しかし、私がPMCからドロップデータベースのサンプルを実行すると、エラーが発生します。dotnet-core ef sql接続
System.ArgumentExceptionの:初期化文字列の形式System.Data.Common.DbConnectionOptions.GetKeyValuePair(文字列れたconnectionString、のInt32 currentPosition、StringBuilderのバッファ、列&キー名でインデックス21 始まる仕様に準拠しません、 (System.Data.Common.DbConnectionOptions..ctor(文字列れたconnectionString、辞書
2 synonyms) at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection.CreateDbConnection() at Microsoft.EntityFrameworkCore.Internal.LazyRef
1.get_Value(AT辞書2 parsetable, String connectionString, Boolean buildChain, Dictionary
2つの同義語) )System.Data.Common.DbConnectionOptions.ParseInternalに文字列&キー値) Microsoft.EntityFrameworkCoreで 。 Design.Internal.DbContextOperations.GetContextInfo(String contextType)Microsoft.EntityFrameworkCore.Design.OperationExecutor.GetContextInfoImpl(String contextType)(Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase)でを呼び出します。 Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(アクションアクション)
で<> c__DisplayClass3_0`1.b__0() はここにここに私のStartup.csクラス
using System.Threading.Tasks;
using Audit.Models.Entity;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Serialization;
namespace Audit
{
public class Startup
{
private IHostingEnvironment _env;
private IConfigurationRoot _config;
public Startup(IHostingEnvironment env)
{
_env = env;
var builder = new ConfigurationBuilder()
.SetBasePath(_env.ContentRootPath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
_config = builder.Build();
}
// 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.AddSingleton(_config);
services.AddDbContext<AuditContext>();
services.AddIdentity<ApplicationUser, IdentityRole>(config =>
{
config.User.RequireUniqueEmail = false;
config.Cookies.ApplicationCookie.LoginPath = "/auth/login";
config.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents()
{
OnRedirectToLogin = async ctx =>
{
if (ctx.Request.Path.StartsWithSegments("/api") && ctx.Response.StatusCode == 200)
{
ctx.Response.StatusCode = 401;
}
else
{
ctx.Response.Redirect(ctx.RedirectUri);
}
await Task.Yield();
}
};
}).AddEntityFrameworkStores<AuditContext>();
services.AddLogging();
services.AddMvc()
.AddJsonOptions(config =>
{
config.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
loggerFactory.AddDebug(LogLevel.Information);
}
else
{
loggerFactory.AddDebug(LogLevel.Error);
}
app.UseStaticFiles();
app.UseIdentity();
app.UseMvc(config =>
{
config.MapRoute(
name: "Default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "App", action = "Index" }
);
});
}
}
}
あるconfigです。 JSON
{
"ConnectionStrings": {
"AuditDbContextConnection": "Server=xxx.xxx.xxx.xxx;Database:databasename;User Id:user;Password:password;"
}
}
ここではAuditContext.cs
です私が間違って行ったことはどこですか?おかげさまで
、および 'パスワード' 必要を「= 'ではなく': '私は確かに '='は有効で、私は見たことがない ':そこには、それは有効ではないと思います。 – gregkalapos
ROFL、私は本当にそれを逃した。 100回私はその部分を見て、私は気づかなかった... –
エイア、私はこれを知っている、それは誰にも起こると思います...それは他の人にそれを示すことが良い理由です。 ;)。 '='の修正は役に立ちますか? – gregkalapos