找不到C#.NET 4.5 ExecuteReaderAsync

时间:2014-02-07 16:02:28

标签: c# .net assemblies

我正在尝试使用ExecuteReaderAsync()异步查询数据库,但是我收到以下错误:

'System.Data.SqlClient.SqlCommand' does not contain a definition for 
'ExecuteReaderAsync' and no extension method 'ExecuteReaderAsync' accepting a first
argument of type 'System.Data.SqlClient.SqlCommand' could be found (are you missing a 
using directive or an assembly reference?)

我正在使用VSE 2012 for Windows Desktop,并且已经安装了.NET 4.5。我正在引用

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.dll

我读过.NET 4.5只是替换4.0,但每当我尝试在4.5目录中选择System.Data.dll时,它都会引用4.0中的那个。不确定这是否重要。

2 个答案:

答案 0 :(得分:5)

  

不确定是否重要。

由于ExecuteReaderAsync在中添加了,我认为确实如此!

  1. 确保您的项目设置为在其项目设置中使用.NET 4.5。

  2. 在添加4.5引用之前,请确保删除任何早期引用。

答案 1 :(得分:1)

选择项目属性并将Target框架设置为.NET Framework 4.5,而不是客户端配置文件。