在使用实体框架时,我已将其拆分为自己的项目:
网站上的所有内容都运行良好。我可以调用Controller并获得有效的模型。当我从Web.Service尝试相同的事情时,我收到此错误:
ERROR:
ConnectionString上的底层提供程序失败 堆叠痕迹:
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
在System.Data.EntityClient.EntityConnection..ctor(String connectionString)
在System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
在System.Data.Objects.ObjectContext..ctor(String connectionString,String defaultContainerName)
在RivWorks.Model.Entities.RivFeedsEntities1..ctor(String connectionString)
在RivWorks.Model.FeedStoreReadOnly..ctor(String connectionString)
在RivWorks.Controller.ProductManager.LookupProduct(String productID,String sku,String urlRef,String env,String logPath)
我有点困惑为什么和挖掘错误日志我终于弄清楚连接字符串没有从网站的配置文件中读取。所以,我添加了一些代码来捕获它,并且,现在,硬编码值。像:
public dataObjects.NegotiateSetup LookupProduct(string productID, string sku, string urlRef, string env, string logPath)
{
string feedConnString = "";
string rivConnString = "";
log.InitializeLogFile(logPath);
dataObjects.NegotiateSetup resultSet = new dataObjects.NegotiateSetup();
try { feedConnString = AppSettings.FeedAutosEntities_connString; }
catch { feedConnString = @"metadata=res://*/Entities.FeedEntities.csdl|res://*/Entities.FeedEntities.ssdl|res://*/Entities.FeedEntities.msl;provider=System.Data.SqlClient;provider connection string='Data Source=***.***.***.***;Initial Catalog=******;Persist Security Info=True;User ID=******;Password="******";MultipleActiveResultSets=True'"; }
try { rivConnString = AppSettings.RivWorkEntities_connString; }
catch { rivConnString = @"metadata=res://*/Entities.RivEntities.csdl|res://*/Entities.RivEntities.ssdl|res://*/Entities.RivEntities.msl;provider=System.Data.SqlClient;provider connection string='Data Source=******;Initial Catalog=******_Dev;Persist Security Info=True;User ID=******;Password="******";MultipleActiveResultSets=True'"; }
try
{
using (RivFeedsEntities1 _dbFeed = new FeedStoreReadOnly(feedConnString).ReadOnlyEntities())
{
using (RivEntities _dbRiv = new RivWorksStore(rivConnString).NegotiationEntities())
{
但是,唉,它仍然给我上述错误!有什么想法吗?
答案 0 :(得分:4)
我知道你一直在用你的连接字符串来清理它们但是我猜你没有把"
放在密码的周围?
他们确实需要吗?
答案 1 :(得分:-1)
仔细检查您的连接字符串是否正确,一点错别字也会导致同样的错误。
这是错误的:
<add name="Entities" connectionString="metadata=res://*/OnlineAB.csdl|res://*/OnlineAB.ssdl|res://*/OnlineABSuperAdmin.msl;provider=System.Data.SqlClient;provider connection string="data source.;initial catalog=
这是对的:
<add name="Entities" connectionString="metadata=res://*/OnlineAB.csdl|res://*/OnlineAB.ssdl|res://*/OnlineABSuperAdmin.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=
查看 DataSource 后面的等号。