实体框架数据库连接错误(Entity framework database connection error)
我第一次使用Entity框架(代码优先)。 我用以下代码创建了一个上下文类。
public class ContactContext : DbContext { public ContactContext() : base("DBConnectionString") { Database.SetInitializer<ContactContext>(new DropCreateDatabaseIfModelChanges<ContactContext>()); } public DbSet<Contact> Contacts { get; set; } }
Web.config文件:
<add name="ContactMgrDBContext" connectionString="Data Source=(Local);Initial Catalog=ContactsDB;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
控制器类:
public class ContactController : Controller { ContactContext db = new ContactContext();
// // GET:/联系人/
public JsonResult ContactList(int? selectedContact) { IQueryable<Contact> contacts = db.Contacts; //contacts.ToList() var contactsJson = JsonConvert.SerializeObject(contacts.ToList()); return Json(contactsJson, JsonRequestBehavior.AllowGet); }
当我在调试模式下运行应用程序时,我在此语句中得到以下异常。
var contactsJson = JsonConvert.SerializeObject(contacts.ToList());
EntityFramework.dll中出现“System.Data.ProviderIncompatibleException”类型的异常但未在用户代码中处理附加信息:从数据库获取提供程序信息时发生错误。 这可能是由实体框架使用不正确的连接字符串引起的。 检查内部异常以获取详细信息,并确保连接字符串正确。
联系班级代码:
public class Contact { [Key] public int ContactId { get; set; } [Required, MaxLength(100)] public string FirstName { get; set; } [Required, MaxLength(100)] public string LastName { get; set; } public string EMail { get; set; } public string Phone { get; set; } public string BusinessName { get; set; } }
I am using the Entity framework (code first) first time. I have created a context class with the following code.
public class ContactContext : DbContext { public ContactContext() : base("DBConnectionString") { Database.SetInitializer<ContactContext>(new DropCreateDatabaseIfModelChanges<ContactContext>()); } public DbSet<Contact> Contacts { get; set; } }
Web.config file:
<add name="ContactMgrDBContext" connectionString="Data Source=(Local);Initial Catalog=ContactsDB;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
Controller class:
public class ContactController : Controller { ContactContext db = new ContactContext();
// // GET: /Contact/
public JsonResult ContactList(int? selectedContact) { IQueryable<Contact> contacts = db.Contacts; //contacts.ToList() var contactsJson = JsonConvert.SerializeObject(contacts.ToList()); return Json(contactsJson, JsonRequestBehavior.AllowGet); }
When I run the application in debug mode, I get the following exception at this statement.
var contactsJson = JsonConvert.SerializeObject(contacts.ToList());
An exception of type 'System.Data.ProviderIncompatibleException' occurred in EntityFramework.dll but was not handled in user code Additional information: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.
Contact class code:
public class Contact { [Key] public int ContactId { get; set; } [Required, MaxLength(100)] public string FirstName { get; set; } [Required, MaxLength(100)] public string LastName { get; set; } public string EMail { get; set; } public string Phone { get; set; } public string BusinessName { get; set; } }
原文:https://stackoverflow.com/questions/30154283
最满意答案
<input zippy ng-model="title">
zippy和ngModel都是以特定顺序呈现的指令。 在这种情况下,zippy会在ngModel之前呈现。 您可以对Maxim Shoustin建议的指令重新排序,也可以通过在指令创建函数上提供
priority
属性来指定渲染顺序,如下所示:.directive('zippy', function($compile){ return { restrict: 'A', priority: -1, replace: true, ...
默认优先级为0.首先呈现具有较高优先级的指令。
<input zippy ng-model="title">
zippy and ngModel are both directives that are render in a specific order. In this case zippy gets rendered before ngModel. You can reorder the directives like Maxim Shoustin suggested or you could specify the rendering order by providing a
priority
attribute on the directive creation function like so:.directive('zippy', function($compile){ return { restrict: 'A', priority: -1, replace: true, ...
The default preority is 0. Directives with higher priorities are rendered first.
相关问答
更多-
指令并不是那里最简单的概念,文档实际上并不是那么好,它分散在各个网站之间。 当我试图编写我的第一个指令时,我拼命compile , pre-compile等,但迄今为止,我从来不需要这些函数。 这可能是由于我缺乏理解,但仍然... 看看你的例子,我看到有一些基本的东西需要澄清。 首先,我会将你的指令限制为E lement,因为它正在取代HTML中的控件。 我会使用A ttribute,例如为现有控件添加功能。 有一个(强制性的)命名约定,您可以在JavaScript中使用HTML中的虚线命名和骆驼套装。 所 ...
-
验证指令将具有隔离范围,因此除非您在编译期间明确提及,否则将无法访问父范围值。 替换fn(scope); by fn(scope.$parent); 更新了Plunker validation directive will have isolated scope and hence parent scope value will not be accessible unless you explicitly mention during compile. Replace fn(scope); by fn(s ...
-
我希望你的$ scope。$ watch逻辑让你失望。 最简单的方法可能是使用$ watchCollection对整个问题数组进行监视: $scope.$watchCollection(questions, function(newValue, oldValue) { for(index=0; indexngModel似乎不适合你想要做的事情。 但无论如何你根本不需要它。 您可以双向绑定某个变量并将名称传递给模型指令范围: app.directive("myDirective", function() { // ... scope: { myModel = "=", modelName = "myModel" // ... } // ... }); app.directive("ngModelDirective", funct ...
在自定义指令中评估角花括号(即编译html模板)(evaluate angular curly brackets(i.e. compile html template) in custom directive)[2022-06-22]
我能够使用自定义指令NgHtmlCompile在指令中编译HTML模板。 我更新了我的plunk - https://plnkr.co/edit/I8ARww?p=preview 参考https://github.com/francisbouvier/ng_html_compile I am able to compile HTML template in directive using custom directive NgHtmlCompile. I have updated my plunk - ht ...AngularJS:如何从控制器中的自定义指令获取模型?(AngularJS : How to get models from custom directive in controller?)[2021-08-15]
// Code goes here var ModuleConfigQuestions = angular.module('ModuleConfigQuestions', [ 'ngRoute', 'ngCookies', 'ngSanitize', 'ui.bootstrap' ] ); ModuleConfigQuestions.directive('customQuestion',function($compile,$sce){ ...zippy和ngModel都是以特定顺序呈现的指令。 在这种情况下,zippy会在ngModel之前呈现。 您可以对Maxim Shoustin建议的指令重新排序,也可以通过在指令创建函数上提供priority属性来指定渲染顺序,如下所示: .directive('zippy', function($compile){ return { restrict: 'A', priority: -1, r ...如果你想将一个参数传递给一个指令你就可以这样做 - 你在问题中所拥有的东西对我来说并不合适。 directive('myDirective', function() { return { restrict: 'EA', scope: { myParam: '=' }, //te ...如何在自定义Angular指令中更改ng-model范围值?(How to change ng-model scope value in custom Angular directive?)[2022-12-17]
在您的link:尝试使用 link:function(scope, element, attrs, ngModel){ scope.$watch('selectedIndex', function(newValue, oldValue) { var item; item = scope.results[newValue]; if (item) { ngModel.$setViewValue(10); ngModel.$re ...最终修改它改变了方法: 最终指令: module.directive('tinymceCustom', function($location, $compile, $q, TinyService, Module, GenerateurPage) { return { restrict: 'A', priority:999, terminal:tr ...相关文章
更多- myEclipse8.5 New DataBase Connection Driver时出错
- The connection to adb is down, and a severe error has occured.
- HTML5 Web SQL Database 数据库
- IOS-Social.framework
- Oracle数据库连接和会话的区别
- Hadoop master connection reset by peer resolution
- Windows Moible, Wince 使用.NET Compact Framework的进行蓝牙(Bluetooth)开发 之 蓝牙虚拟串口 (Bluetooth Virtual Serial Port)
- Mysql错误:Ignoring query to other database解决方法
- AMF: ASP.NET Mobile Framework
- 项目中用连接池管理Connection,connection用完后还关闭吗?
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)