【问题标题】:"DataReader.GetFieldType(...) returned null" on Azure WebsiteAzure 网站上的“DataReader.GetFieldType(...) 返回 null”
【发布时间】:2014-04-09 17:02:18
【问题描述】:

我有一个在 Azure 上运行的网站。我正在从具有“地理”类型的列的 SQL Server 数据库表中提取数据。这会导致“DataReader.GetFieldType(...) 返回 null

的错误

网络上的消息来源说我必须包含已添加到 web.config 和 bin 文件夹中的 Microsoft.SqlServer.Types.dll,但错误仍然存​​在。我错过了什么?

代码:

    SqlConnection Connection = NewConnection();
    SqlDataAdapter da = new SqlDataAdapter(SQL, Connection);
    DataTable dt = new DataTable();
    da.Fill(dt);

【问题讨论】:

  • 你能发布你的连接字符串(显然减去登录信息)吗?
  • 连接字符串 "Server=tcp:SERVER-NAME,1433;Database=DATABASE-NAME;User ID=SQL-USERNAME;Password=PASSWORD;Trusted_Connection=False;Encrypt=True;Connection Timeout=5 ;"
  • 您是通过“添加引用”在项目中添加了对Microsoft.SqlServer.Types.dll的引用,还是只是手动将其添加到bin文件夹中?

标签: c# sql-server azure ado.net


【解决方案1】:

我们在使用 Microsoft.SqlServerTypes 时遇到了许多问题,我们采取的措施之一是将其添加到 web.config 或 app.config 文件中,以确保目标 dll 的正确版本.

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
    <bindingRedirect oldVersion="10.0.0.0" newVersion="11.0.0.0" />
  </dependentAssembly>

【讨论】:

    【解决方案2】:

    您可以引用 Microsoft.SqlServer.Types 并在其属性中设置“复制本地”。应该有帮助。

    【讨论】:

      猜你喜欢
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多