我开始创建 VB.Net 类库项目,但无法使 edmx 连接正常工作。我可以毫无问题地将 edmx 连接添加到其他项目类型。我对创建类库和 VB.Net 有点陌生,更习惯于 MVC C#。
我在其他帖子中尝试过建议,确保连接在 app.config 中,但无济于事。
实例化 myEntities 时,出现错误:
No connection string named 'myEntities' could be found in the application config file.
这是代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim context As New MyEntities()
Dim query = From items In context.mytable Order By items.ID Select items
End Sub
虽然我不确定它是否需要,但这里是 app.config 中的连接
<connectionStrings><add name="myEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=myDBSERVER;initial catalog=myTable;persist security info=True;user id=myuserid;password=mypassword;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings></configuration>