什么是代码中的连接字符串首先在mvc

什么是代码中的连接字符串首先在mvc

本文介绍了什么是代码中的连接字符串首先在mvc中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好 i想在我的CodeFirst Mvc项目中使用sqlconnection。 我的connectionstring不在web.config中。 i见下面的内容在ProductContecxt中:helloi wanna use sqlconnection in my CodeFirst Mvc Project.my connectionstring is not in web.config.i see something like below in ProductContecxt:public ProductContext():base(SharedDll.Connections.ConnectionString()) 是否正确? 我该怎么用呢在我使用之前的连接字符串中。is it correct?how can i use it in my connection string like before i used.//before: String connectionstring = "DataSource=.\SQLEXPRESS;" + "Initial Catalog=DEMO;" + "Integrated Security=True"; 但是现在如何在connectionstringbut now how can use public ProductContext()... in connectionstring推荐答案protected void Application_Start() { DataCatalog.ConnectionString = ConfigurationManager.ConnectionStrings["PawLoyalty"].ConnectionString; } Web.configWeb.config<connectionStrings> <add name="PawLoyalty" connectionString="Server=.;database=PawLoyalty;Trusted_connection=true;pooling=true;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /> </connectionStrings> DataCatalog.cs b $ bDataCatalog.cspublic class DataCatalog : DbContext { public static string ConnectionString { get; set; } public DataCatalog() : base(ConnectionString) { }} 我希望这会对你有所帮助。I hope this will help to you. 这篇关于什么是代码中的连接字符串首先在mvc中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-30 03:39