asp.net-mvc – 获取错误参数’nameOrConnectionString’不能为n
发布时间:2020-12-16 07:11:00 所属栏目:asp.Net 来源:网络整理
导读:我在azure云存储上使用我的数据库和其他存储.我正在使用实体代码首次使用但问题是当我尝试使用CloudConfigurationManager.GetSetting()从云存储中读取连接字符串时,我收到以下错误: 错误:参数’nameOrConnectionString’不能为null,为空或仅包含空格. Enti
我在azure云存储上使用我的数据库和其他存储.我正在使用实体代码首次使用但问题是当我尝试使用CloudConfigurationManager.GetSetting()从云存储中读取连接字符串时,我收到以下错误:
错误:参数’nameOrConnectionString’不能为null,为空或仅包含空格. 这是我的Azure项目:Demo.Web.Azure 它有2个配置文件: 1)ServiceConfiguration.Cloud.cscfg: <Role name="Demo.Web"> <Setting name="MyConnectionString" value="Server=----;Database=DemoEntity;User ID=---;Password=---&w;Trusted_Connection=False; Encrypt=True;MultipleActiveResultSets=True;" /> <Setting name="Demo.Storage" value="DefaultEndpointsProtocol=https;AccountName=---;AccountKey=------" /> 2)ServiceConfiguration.Local.cscfg: <Role name="Demo.Worker"> <Setting name="Demo.Storage" value="DefaultEndpointsProtocol=https;AccountName=---;AccountKey=------" /> 3)ServiceDefinition.csdef中: <ServiceDefinition name="Demo.Web.Azure" schemaVersion="2014-06.2.4"> <WebRole name="RepuGuard.Web" vmsize="Small"> <ConfigurationSettings> <Setting name="MyConnectionString" /> <Setting name="Demo.Storage" /> </ConfigurationSettings> </WebRole> <WorkerRole name="Demo.Worker" vmsize="Small"> <ConfigurationSettings> <Setting name="MyConnectionString" /> <Setting name="Demo.Storage" /> </ConfigurationSettings> </WorkerRole> </ServiceDefinition> 这是我的Context文件,它读取数据库连接字符串: public partial class MyDemoDBContext : DbContext,IDisposable { public ObjectContext Context { get; set; } public MyDemoDBContext() : base(CloudConfigurationManager.GetSetting("MyConnectionString"))//Getting Error here { Context = ((IObjectContextAdapter)this).ObjectContext; } public MyDemoDBContext (string connectionString) : base(connectionString) { Context = ((IObjectContextAdapter)this).ObjectContext; } } 在这里得到错误: public MyDemoDBContext() : base(CloudConfigurationManager.GetSetting("MyConnectionString")) { Context = ((IObjectContextAdapter)this).ObjectContext; } 解决方法
如果您有多个项目正在解决方案,尝试设置启动项目将解决此问题.(sry延迟)
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-4 – 如何在MVC4 C#中安排任务?
- asp.net-mvc – DropDownListFor在编辑视图上不重复的项目(
- Asp.Net Identity – 登录后更新声明
- asp.net-mvc – 在ASP.NET MVC中,使用@RenderSection(与@Re
- ASP.NET linq选择多个连接
- Asp.Net Core简介与安装教程
- asp.net-mvc – 通过使用EF 4.1 DBContext为SaveChanges分配
- asp.net – IQueryable和存储库 – 需要2?
- asp.net – 如何在客户端验证失败后保持滚动位置?
- asp.net-mvc – 可以在ASP.NET MVC中停止表单的多个回发的方
推荐文章
站长推荐
- c#中@标志的作用
- asp.net-mvc – 同一页面上的ASP.NET MVC模型绑定
- asp.net-web-api – 构造函数依赖注入WebApi属性
- asp.net – 在fileupload中选择立即调用C#函数文
- asp.net-mvc-5 – 当EnableOptimizations为true时
- asp.net-mvc – 如何在ASP.NET Razor MVC4视图中
- asp.net – 从aspx页面中的Static方法访问ViewSt
- asp.net – jQuery单击事件处理程序被调用两次复
- asp.net – 在数据库中存储日期时间?
- asp.net-core – Visual Studio 2015中的ASP.NET
热点阅读