如何解决ASP.NET DataContext连接错误

编程入门 行业动态 更新时间:2024-10-09 15:24:04
本文介绍了如何解决ASP.NET DataContext连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的ASP.NET网站出现以下错误.我刚刚将其移至另一台PC. IIS正在运行,SQL Server Express&将数据源"计算机名称更改为新的计算机名称.但是,在任何具有数据库访问权限的页面上,都会出现屏幕截图中显示的错误:

I have the following error with my ASP.NET web site. I have just moved it to another PC. Got IIS running, SQL Server Express & changed the Data Source machine name to the new machine name. However on any page with DB access, I get the error shown in the screenshot:

innovations-news.aspx创建一个新的DataContext,从而:

innovations-news.aspx creates a new DataContext thus:

dataContext = new DataContext(Config.ConnectionString);

我的Config类根据当前IP返回连接字符串.例如:

My Config class returns the connection string based on current IP. For example:

return ConfigurationManager.ConnectionStrings["Development"].ConnectionString;

哪个在web.config中:

Which is in web.config:

<connectionStrings> <add name="Development" connectionString="Data Source=WORK51C0\SQLEXPRESS;Initial Catalog=Jri;Integrated Security=True;" providerName="System.Data.SqlClient"/> </connectionStrings>

以下是来自LinqToSql1.designer.cs

The following is from LinqToSql1.designer.cs

public DataContext() : base(global::Jri.Data.Properties.Settings.Default.JriConnectionString1, mappingSource) { OnCreated(); } public DataContext(string connection) : base(connection, mappingSource) { OnCreated(); } public DataContext(System.Data.IDbConnection connection) : base(connection, mappingSource) { OnCreated(); } public DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : base(connection, mappingSource) { OnCreated(); } public DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : base(connection, mappingSource) { OnCreated(); }

关于如何最好地调试它的任何建议?也许甚至您知道怎么了?!

Any advice on how best to debug this? Or perhaps even you know whats wrong?!

谢谢

推荐答案

好的,这是Configuration Manager的My Config类的访问问题.因此,我的临时解决方案是让此类直接输出连接字符串,而不是尝试从web.config中获取它.

OK well this was an access problem that My Config class with ConfigurationManager. So my temporary solution has been to have the connection string directly outputted by this class rather than try to get it from web.config.

更多推荐

如何解决ASP.NET DataContext连接错误

本文发布于:2023-11-25 09:23:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629204.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何解决   错误   NET   ASP   DataContext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!