如何解决ASP.NET DataContext连接错误 [英] How to resolve ASP.NET DataContext connection error

查看:168
本文介绍了如何解决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连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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