【发布时间】:2015-06-20 20:20:47
【问题描述】:
我是 ASP.NET 新手,发现连接字符串很难掌握。
我已经成功连接了下面的 2 个连接字符串,用于数据库安全的连接字符串工作正常,但我无法让处理其余数据的主字符串工作。我想一定是因为连接字符串的Entity Framework元素。
对于元数据部分,我使用了res://*/ 部分,因为我认为这效率较低,但如果我正确理解了我一直在阅读的文档,它会抓住一切。
<remove name="ApplicationServices" />
<add name="ApplicationServices"
connectionString= "Server=184.168.194.64,1433;
Database= myASPNETDB;
User=****;
Password=****;"
providerName="System.Data.SqlClient" />
<remove name="PropManEntities" />
<add name="PropManEntities"
connectionString="Metadata=res://*/;
provider=System.Data.SqlClient;
provider connection string='Data Source=184.168.194.64,1433;
Initial Catalog=myTest_C;
User=****;
Password=****;
multipleactiveresultsets=true'"
providerName="System.Data.EntityClient" />
当我打开包含数据的页面时出现以下错误:
The query syntax is not valid. Near line 6, column 17.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.EntitySqlException: The query syntax is not valid. Near line 6, column 17.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[EntitySqlException: The query syntax is not valid. Near line 6, column 17.]
System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +964
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.DetailsView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.DetailsView.EnsureDataBound() +223
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()+75
System.Web.UI.Control.EnsureChildControls() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
GoDaddy 不愿意就此事提供任何帮助。
编辑:
在尝试了 Matteo 的建议后,我收到了以下错误:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.]
System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +8425830
System.Data.EntityClient.EntityConnection..ctor(String connectionString) +43
System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString) +85
System.Data.Objects.ObjectContext..ctor(String connectionString) +12
System.Web.UI.WebControls.EntityDataSourceView.ConstructContext() +461
System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +102
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.DetailsView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.DetailsView.EnsureDataBound() +223
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()+75
System.Web.UI.Control.EnsureChildControls() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Control.PreRenderRecursiveInternal() +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)+974
【问题讨论】:
-
您是先使用代码还是从数据库生成 .edmx?
-
我不认为 Metadata=res://*/ 正在工作,如果是的话,不要认为这真的很方便,因为如果你使用多个它会导致问题,例如来自其他组件的模型。尝试设置正确的 .csdl、.ssdl 和 .msl(如果您不知道它必须是什么,请重新添加一个 edmx 并让它为您创建连接字符串)。
-
我没看错,您在两个不同的数据库中有数据?
-
@Claies 是的,没错,一个用于处理安全性的 aspnetdb 数据库,一个用于主数据库。我不知道我是否可以将两者结合起来。
-
@MrBliz 我从数据库中生成了一个 .edmx。
标签: c# asp.net .net entity-framework