【发布时间】:2012-03-24 08:53:42
【问题描述】:
我有一个基于 Azure/Cloud 的项目(仅限单个项目)。它在项目中添加了一个 WCF/WebRole。我的 WCF 服务使用实体框架与 SQLAzure 数据库通信。这工作得很好。
在项目的 web.config 中,我有以下内容:
<connectionStrings>
<add name="CommuteEntities" connectionString="metadata=res://*/Db.CommuteDataModel.csdl|res://*/Db.CommuteDataModel.ssdl|res://*/Db.CommuteDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=<db-here>.database.windows.net;initial catalog=dandr;persist security info=True;user id=<user-id-here>;password=<password-here>;multipleactiveresultsets=True;App=EntityFramework" " providerName="System.Data.EntityClient" />
</connectionStrings>
到目前为止一切都很好。所以我想做少量的预定后台处理(基于计时器而不是传入请求)。它的任务太小,不足以证明为该工作启动 WorkerRole 是合理的。
因此,我在 WebRole 项目 WebRole.cs 中创建了类似以下内容的内容@
public override void Run()
{
while (true)
{
//This is for debug purposes:
string str = ConfigurationManager.ConnectionStrings["CommuteEntities"].ToString();
BackgroundProcessing.BackgroundProcessing.BackgroundProcess();
Thread.Sleep(150000); //2.5mins
}
}
由于某种原因,获取连接字符串的行似乎不起作用。但是,将相同的代码放入 WCF 服务中效果很好。
强调一下,此解决方案中只有一个项目,WebRole.cs 与工作的 WCF 服务位于同一项目中。
注意:获取连接字符串仅用于调试目的。我遇到的根本问题是,当我的 WebRole.cs 尝试访问实体时,它会收到以下异常消息:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
注意 2::我刚刚注意到我的WebRole.cs 中的任何内容似乎都看不到Web.config 文件中已配置的任何内容。是不是我做的不对或者有什么误解?
有人遇到过这个或者有什么想法吗?
【问题讨论】:
标签: c# .net database entity-framework azure