2015-06-20 120 views
1

我是ASP.NET新手,很難找到連接字符串。2連接字符串,安全字符串工作,實體框架1不是

我已經成功連接了下面2個連接字符串,數據庫安全性的連接字符串工作正常,但我無法獲得處理其餘數據的主字符串的工作。我認爲它必須是因爲連接字符串的實體框架元素。

對於元數據部分,我已經使用了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的不願意提供這個方面的任何幫助。

編輯:

試圖利瑪竇的建議後,我得到了以下錯誤:

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 
+0

您是先使用Code還是從數據庫生成.edmx? – MrBliz

+1

我不認爲元數據= res:// * /正在工作,如果是這樣,不要認爲這很方便,因爲如果您使用多個元數據,則會導致問題。來自其他組件的模型。嘗試設置正確的.csdl,.ssdl和.msl(如果您不知道它是什麼,請重新添加一個edmx並讓它爲您創建連接字符串)。 – Dacker

+0

我讀到這個權利,你有兩個單獨的數據庫中的數據? – Claies

回答

0

試試這個

<add name="PropManEntities" connectionString="data source=184.168.194.64,1433;initial catalog=myTest_C;User Id=****;Password=****;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /> 

對不起,我沒你使用EDMX實現文件.. 試試這個版本(而不是使用你的文件名):

<add name="PropManEntities" connectionString="metadata=res://*/??????????.csdl|res://*/????????????.ssdl|res://*/???????????????.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=184.168.194.64,1433;initial catalog=MPInvoicingSystem;user id=*****;password=*****;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 

如果這不起作用,我建議您添加一個新的edmx模型並複製自動添加的連接字符串。 Matteo

+0

感謝您的建議,請參閱編輯後的問題,以獲取我在嘗試使用時收到的新錯誤消息。謝謝 – matty

+0

嗨@Matteo我一直在試圖理解連接字符串的.csdl,.ssdl和.msl文件元素。我的印象是這些包含在.edmx文件中。但是,當我編譯我的項目時,我注意到包含.edmx文件的DAL目錄不是編譯元素之一。我是否需要嘗試創建這些文件,還是需要更改連接字符串? – matty