实体框架连接字符串麻烦 [英] Entity Framework Connection String Trouble

查看:93
本文介绍了实体框架连接字符串麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个小库(DLL)来管理用户和他们的角色/权限。该计划是要能够这个DLL添加到一个MVC项目,并能够处理用户/角色/等。所有的数据都驻留在一个SQL数据库。

I am making a little library(DLL) to manage users and their roles/privileges. The plan is to be able to add this dll to an MVC project and be able to manipulate users/roles/etc. All the data resides in a SQL db.

我使用的数据访问实体框架。

I am using entity framework for data access.

所以,当我初始化一个新的RoleManager(这是我做的lib主类的名称)我用的connectionString提供它像这样:

So when I initialize a new RoleManager(this is the name of the main class in the lib I'm making) I supply it with a connectionString like so:

RoleManager roleManager = new RoleManager(string connectionString);



然后在构造函数中我这样做:

Then inside the constructor I do this:

db = new RoleManagerEntities(connectionString); //This is the EntityFramework

和我想提供这种连接字符串(以及许多其他)

And I am trying to supply this connection string (among many others)

"metadata=res://*/RoleManager.csdl|res://*/RoleManager.ssdl|res://*/RoleManager.msl;provider=System.Data.SqlClient;provider connection string='Data Source=localhost;Initial Catalog=Login;Integrated Security=True;Connection Timeout=60; multipleactiveresultsets=true'"

和我得到以下错误:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.



这个问题是有试图从我的新项目实例化EF不提供的结果一个连接字符串,也不必我的应用程序配置为它默认为内部的任何物件。可惜我现在不能将其删除。

推荐答案

就在连接字符串信息从您的DLL配置文件复制您可执行的配置文件。

Just copy the connection string information from your DLL config file to your executable config file.

这篇关于实体框架连接字符串麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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