asp.net-mvc – Visual Studio 2012 ASP.NET MVC连接字符串Web.C
发布时间:2020-12-16 03:55:36 所属栏目:asp.Net 来源:网络整理
导读:我有一个查询数据库的Visual Studio 2012 ASP.NET MVC应用程序.我被告知最好将连接字符串保存在web.config文件中.名为ConnString的连接字符串位于: connectionStrings add name="ConnString" connectionString="Data Source=IP_OF_SERVER,PORT; Initial Cat
我有一个查询数据库的Visual Studio 2012 ASP.NET MVC应用程序.我被告知最好将连接字符串保存在web.config文件中.名为ConnString的连接字符串位于:
<connectionStrings> <add name="ConnString" connectionString="Data Source=IP_OF_SERVER,PORT; Initial Catalog=DATABASE_NAME; UID=USERNAME; pwd=PASSWORD; Integrated Security=True;"/> </connectionStrings> 在C#中我想获取连接字符串,我使用: String connStr = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; 应用程序在此行上死亡并抛出以下异常: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. 我包括: using System.Configuration; 在页面顶部,但它仍然失败.我尝试使用System.WebConfiguration,但我仍然无法获取字符串.我如何获得字符串? 解决方法
将您的web.config文件更改为包含providerName =“System.Data.SqlClient”作为连接字符串的属性,如下所示:
<connectionStrings> <add name="ConnString" connectionString="Data Source=IP_OF_SERVER,PORT; Initial Catalog=DATABASE_NAME; UID=USERNAME; pwd=PASSWORD; Integrated Security=True;" providerName="System.Data.SqlClient" /> </connectionStrings> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- AutoMapper在asp.netcore中的使用
- asp.net – 如何从服务器控件中删除’name’属性?
- asp.net-mvc – Web Api调用返回404错误,GUID作为参数传递
- ASP.NET MVC 3中建立的[Email]属性是不是?
- asp.net-mvc-3 – 基于域的ASP.net MVC 3输出缓存
- 你能在每个动作上在ASP.NET-MVC中应用ActionFilter吗?
- asp.net-mvc-4 – 无法让ASP.NET 4 Web API返回状态代码“2
- asp.net-mvc – 在ASP.Net MVC中,如何创建将javascript和cs
- asp.net – 我可以在docker容器中运行IIS上托管的dotnet应用
- TFS 2015构建:是否可以在存储库映射中使用变量?
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC和混合模式认证
- asp.net-mvc – 在视图ASP.NET MVC 4中禁用所需的
- asp.net-mvc – MVC路由错误:约束条目’长度’
- ASP.NET AJAX工具包 – CalendarExtender在Postb
- asp.net-mvc – JSP相当于ASP.NET MVC的部分视图
- 如何在SDL Tridion页面上呈现asp.net用户控件?
- asp.net-mvc-3 – Azure ACS – 最佳实践实施
- asp.net-mvc – 我应该让MVC处理我的favicon请求
- asp.net-mvc – HandleErrorAttribute无法正常工
- asp-classic – 我使用经典的ASP,IIS6和WinServe
热点阅读