【问题标题】:Failed to generate code error when compiling a ASP.NET website on a new computer在新计算机上编译 ASP.NET 网站时无法生成代码错误
【发布时间】:2013-07-29 01:40:57
【问题描述】:

我通过复制网站的整个文件夹将我的 ASP.NET 4.5 网站移到了新计算机上。当我尝试在 Visual Studio 2012 的新计算机上构建网站时(与第一台计算机上的版本相同),我收到一些警告和错误。

错误:

Failed to generate code. Exception of type 'System.Data.Design.InternalException' was thrown.   C:\Users\admin\Desktop\website_sample\App_Code\DataSet.xsd  

有 21 个警告,都针对不同的 dll 文件说“无法更新自动刷新参考”

当我尝试运行我的 default.aspx 页面(在第一台计算机上运行良好)时,我收到 App_Code/DataSet.xsd 文件的以下错误:

Failed to generate code. Exception of type 'System.Data.Design.InternalException' was thrown.

还有源错误:

Line 1:  <?xml version="1.0" encoding="utf-8"?>
Line 2:  <xs:schema id="DataSet" targetNamespace="http://tempuri.org/DataSet.xsd" xmlns:mstns="http://tempuri.org/DataSet.xsd" xmlns="http://tempuri.org/DataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
Line 3:    <xs:annotation>

我正在使用 MySQL .NET 连接器,但我已经在新计算机上安装了它以确保这不会导致错误。

我需要知道如何解决错误和警告。我最关心的首先是这个错误,因为它阻止我运行一些我今天需要运行的任务。提前致谢。

我的假设是我使用了不同版本的 .NET MySQL 连接器,但我不敢。

【问题讨论】:

  • 您的 XSD 文件中是否有 ConnectionStringObject 属性?

标签: asp.net visual-studio-2012 compiler-errors mysql-connector asp.net-4.5


【解决方案1】:

如果您最初通过从 Visual Studio 中的数据库或服务器资源管理器中拖放来创建数据集,并且在某些时候数据库引用不再有效(移动/删除数据库),则会导致此异常。

这是因为 Visual Studio 将连接字符串存储在 XSD 中。如果该连接字符串不再有效,则无法动态生成所需的适配器。要解决此问题,请更改 XSD 文件内 Connection 节点上的 ConnectionStringObject 属性(不是在设计级别,而是在文本编辑器级别。)将其设置为指向您的数据集对应的数据库的有效连接字符串,并且您正在很好。

【讨论】:

    【解决方案2】:

    如果您不再关心连接,则可以改为删除 Connection 元素,留下一个空的 Connections 节点。

    ...
    <DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
        <Connections />
        <Tables />
        <Sources />
    </DataSource>
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-27
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      相关资源
      最近更新 更多