【问题标题】:How to resolve ASP.NET DataContext connection error如何解决 ASP.NET DataContext 连接错误
【发布时间】:2012-05-20 07:07:47
【问题描述】:

我的 ASP.NET 网站出现以下错误。我刚把它移到另一台电脑上。运行 IIS,SQL Server Express 并将数据源机器名称更改为新机器名称。但是,在任何具有数据库访问权限的页面上,我都会收到屏幕截图中显示的错误:

innovations-news.aspx 这样创建了一个新的 DataContext:

dataContext = new DataContext(Config.ConnectionString);

My Config 类根据当前 IP 返回连接字符串。例如:

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

在 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

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();
    }

关于如何最好地调试它有什么建议吗?或者,也许你也知道出了什么问题?!

谢谢,

【问题讨论】:

  • WORK51C0 是新工作站的名称吗?它是否具有具有该实例名称的 SQL Express,并且是否已打开集成安全性?可以连接 Sql Server Management Studio 吗?
  • connection 还是 mappingSource 为空?
  • 您的 Jri.Data.DataContact 是否派生自 Linq.DataContext?我们可以使用更多信息...
  • 好吧,我在 Windows 7 家庭版上,我刚刚发现它不支持 Windows 身份验证。我能做些什么呢?
  • 刚刚更新了来自 LinqToSql1.designer.cs 的 DataContext 函数

标签: c# asp.net sql-server iis


【解决方案1】:

这是一个 ArgumentNullException。您以某种方式将 null 传递给构造函数或 DataContext。

附加一个调试器,看看为什么 Config.ConnectionString 或 mappingSource 返回 null。

【讨论】:

    【解决方案2】:

    好吧,这是我的配置类与 ConfigurationManager 的访问问题。所以我的临时解决方案是让这个类直接输出连接字符串,而不是尝试从web.config中获取。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-28
      • 2018-01-28
      • 2021-01-23
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多