实体SQLCE在app.config文件中找不到连接字符串 [英] Entity SQLCE Can't find connection string in app.config file

查看:147
本文介绍了实体SQLCE在app.config文件中找不到连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


没有连接字符串名称为PFModelContainer可能是在
应用程序配置文件中找到。


我的edmx文件在一个单独的项目中。我检查了app.config文件,我的模型在那里,我也把它放在我的主项目app.config文件中。仍然不行这是连接字符串:

 < connectionStrings> 
< add name =PFModelContainer
connectionString =metadata = res://*/PFModel.csdl | res:
//*/PFModel.ssdl|res://* /PFModel.msl;
provider = System.Data.SqlServerCe.3.5;
provider连接字符串=& quot;
数据源= C:\Documents and Settings\Jon\我的文件\Visual
Studio 2010 \Projects\SpreadsheetAddIn
\SpreadsheetAddIn\bin\Debug\PFData.sdf;
Password = password& quot;
providerName =System.Data.EntityClient/>
< / connectionStrings>

以下是上下文的调用方式:

 私人mdbContext作为新的PFModelContainer 

哪些到: p>

 部分公共类PFModelContainer 
继承DbContext

Public Sub New()
MyBase .New(name = PFModelContainer)
End Sub

我以为答案会类似于这个人发生的 。但是不幸的是他的解决方案与我的工作不一致。



更新:



我注意到,在我打这个代码之前,这个错误并没有被捕获。当我在第三行执行linq查询时,会发生。

  Dim dbContext作为新的PFModelContainer 
Dim dbAccount As IQueryable (帐户)
dbAccount =从a在dbContext.Accounts
其中(a.AccountName =Hello)
选择

更新(我已经尝试过连接字符串 - 我记得):



1 主要项目: - > 默认创建

 < add name =PFModelContainer
connectionString =metadata = res://*/PFModel.csdl |
res://*/PFModel.ssdl |
res:// * / PFModel.msl;
provider = System.Data.SqlServerCe.3.5;
provider连接字符串=& quot;
数据源= C:\Documents和Settings\Jon\\ \\ My Documents\Visual Studio 2010 \Projects\SpreadsheetAddIn\PFDatabase\bin\Debug \\PFData.sdf;
密码=密码&安培; QUOT;
providerName =System.Data.EntityClient/>

图书馆:

 < add name =PFModelContainer
connectionString =metadata = res://*/PFModel.csdl |
res:// * / PFModel .ssdl |
res://*/PFModel.msl;
provider = System.Data.SqlServerCe.3.5;
provider connection string =& quot;
数据源= | DataDirectory | \bin\Debug\PFData.sdf;
Password = password& quot;
providerName =System.Data.EntityClient/>

2主要项目: - > 用PFDatabase替换*

 < add name =PFModelContainer
connectionString =metadata = res:// PFDatabase /PFModel.csdl |
res://PFDatabase/PFModel.ssdl |
res://PFDatabase/PFModel.msl;
[... Same ...]

库:
[...相同的修改...]



3主要项目: - >替换res:// * / with .\

 < add name =PFModelContainer
connectionString =metadata = .\PFModel.csdl |
.\PFModel.ssdl |
.\PFModel.msl;
[...相同...]

库:
[...相同的修改...]



4主要项目: - >替换res:/ / * / with〜\

 < add name =PFModelContainer
connectionString =metadata =〜 \\ PFModel.csdl |
〜\PFModel.ssdl |
〜\PFModel.msl;
[...相同...]

图书馆:
[...相同的修改...]

解决方案

从这个专家交流中得到一些帮助,结束了一个工作(不知道为什么不这样做),因为我使用DbContext而不是EntityObject我不得不创建自己的可重写过程,如下面的第二个:

  Public Sub New()
MyBase.New(name = PFModelContainer)
End Sub

Public Sub New(ByVal connectionString As String)
MyBase.New(connectionString)
End Sub

然后,我必须创建自己的连接字符串,这基本上是原始代码生成的,所以我不知道为什么它不能从app.config文件中工作。也许在程序中有一个错误,将修复下一步?希望是这样,或者我做错了事,神秘。


I've been getting this error when I try and use my model container:

No connection string named 'PFModelContainer' could be found in the application config file.

I have my edmx file in a separate project. I checked the app.config file and my model was there, and I also put it in my main project app.config file. Still doesn't work. Here's the connection string:

    <connectionStrings>
        <add name="PFModelContainer" 
             connectionString="metadata=res://*/PFModel.csdl|res:
                               //*/PFModel.ssdl|res://*/PFModel.msl;
             provider=System.Data.SqlServerCe.3.5;
             provider connection string=&quot;
             Data Source=C:\Documents and Settings\Jon\My Documents\Visual
                         Studio 2010\Projects\SpreadsheetAddIn
                         \SpreadsheetAddIn\bin\Debug\PFData.sdf;
             Password=password&quot;" 
             providerName="System.Data.EntityClient" />
    </connectionStrings>

Here's how the context is called:

Private mdbContext As New PFModelContainer

Which goes to:

Partial Public Class PFModelContainer
    Inherits DbContext

    Public Sub New()
        MyBase.New("name=PFModelContainer")
    End Sub

I thought the answer would be similar to what happened to this guy. But unfortunately his solution doesn't work with mine.

Update:

I've noticed the error isn't caught until I hit this code. It occurs when I do the linq query on the third line.

Dim dbContext As New PFModelContainer
Dim dbAccount As IQueryable(Of Account)
dbAccount = From a In dbContext.Accounts
            Where (a.AccountName = "Hello")
            Select a

Update (What I've tried for connection strings - that I can remember):

1 Main Project: --> Default Creation

<add name="PFModelContainer" 
     connectionString="metadata=res://*/PFModel.csdl|
                                res://*/PFModel.ssdl|
                                res://*/PFModel.msl;
     provider=System.Data.SqlServerCe.3.5;
     provider connection string=&quot;
       Data Source=C:\Documents and Settings\Jon\My Documents\Visual Studio 2010\Projects\SpreadsheetAddIn\PFDatabase\bin\Debug\PFData.sdf;
       Password=password&quot;" 
     providerName="System.Data.EntityClient" />

Library:

<add name="PFModelContainer" 
     connectionString="metadata=res://*/PFModel.csdl|
                                res://*/PFModel.ssdl|
                                res://*/PFModel.msl;
     provider=System.Data.SqlServerCe.3.5;
     provider connection string=&quot;
     Data Source=|DataDirectory|\bin\Debug\PFData.sdf;
       Password=password&quot;" 
       providerName="System.Data.EntityClient" />

2 Main Project: --> Replace * with PFDatabase

<add name="PFModelContainer" 
     connectionString="metadata=res://PFDatabase/PFModel.csdl|
                                res://PFDatabase/PFModel.ssdl|
                                res://PFDatabase/PFModel.msl;
                                [...Same...]

Library: [...Same w/ modifications...]

3 Main Project: --> Replace res://*/ with .\

<add name="PFModelContainer" 
     connectionString="metadata=.\PFModel.csdl|
                                .\PFModel.ssdl|
                                .\PFModel.msl;
                                [...Same...]

Library: [...Same w/ modifications...]

4 Main Project: --> Replace res://*/ with ~\

<add name="PFModelContainer" 
     connectionString="metadata=~\PFModel.csdl|
                                ~\PFModel.ssdl|
                                ~\PFModel.msl;
                                [...Same...]

Library: [...Same w/ modifications...]

解决方案

Got some help from experts exchange on this one. Ended up doing a work around (not sure why it wasn't working like it should), since I'm using DbContext instead of EntityObject I had to create my own overrideable procedure like (the second one below):

Public Sub New()
   MyBase.New("name=PFModelContainer")
End Sub

Public Sub New(ByVal connectionString As String)
   MyBase.New(connectionString)
End Sub

I then had to create my own connection string, which is basically what the original code generated, so, I'm not sure why it wasn't working from the app.config file. Maybe there's a bug in the program that will be fixed the next go around? Hopefully that was it, either that or I did something wrong, mystery.

这篇关于实体SQLCE在app.config文件中找不到连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆