简体   繁体   English

ASP.NET MVC C#连接字符串元数据创建

[英]ASP.NET MVC C# Connection String metadata creation

Sorry, I have a feeling this is a really basic question, but my connection string to my data source is invalid. 抱歉,我觉得这是一个非常基本的问题,但是我到数据源的连接字符串无效。 I did a bit of trouble shooting and think that I am missing the metadata part of the connectionstring - but I'm not sure where it is/how to create it. 我在拍摄时有些麻烦,并认为我缺少连接字符串的元数据部分-但我不确定它在哪里/如何创建。

How is how I think it should look 我觉得应该如何看

<add name="PDCWebEntities" connectionString="metadata=METADATASTRING;Data Source=.;Initial Catalog=PDC;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

And here is where I think the information that needs to be in the metadata string is held: 这是我认为需要保存在元数据字符串中的信息的位置:

实体

It should be noted that the app.config file where the connectionstring is is in the PokemonDayCareSimple.Web project 应该注意的是,连接字符串所在的app.config文件在PokemonDayCareSimple.Web项目中

Is it possible to make the metadata part of the string from this information? 是否可以根据此信息使元数据成为字符串的一部分?

You don't need metadata for connectionString. 您不需要connectionString的元数据。

<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\me\source\repos\MarketplaceMVC\MarketplaceMVC.Web\App_Data\MarketplaceIdentityDb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

Instead of "AttachDbFilename" you can use also "Initial Catalog". 除了“ AttachDbFilename”,您还可以使用“初始目录”。

在此处输入图片说明

In your Context Class you need to add a constructor: 在上下文类中,您需要添加一个构造函数:

public ApplicationContext() : base("DefaultConnection")
{

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM