Ric*_*ick 1 .net sql t-sql sql-server-2000
我有一个Web应用程序,我在两个连接表上调用SELECT DISTINCT查询.如果我尝试从网页运行查询,我会收到以下错误:"text,ntext或image数据类型不能被选为DISTINCT".当我从SQL Management Studio中运行它时,查询运行正常 - 没有错误.更有趣的是,任何一个表中都没有text,ntext或image数据类型.
应该注意的是,我正在逐步执行代码,并且在执行查询之前,我正在将查询从"监视"窗口复制到Mgmt Studio中,当我单步执行并让.NET运行时,它会运行它,错误被抛出.我正在使用.NET 2和System.Data.SqlClient命名空间.
这是我的查询:
SELECT DISTINCT ResponseFormParent.*
FROM ResponseFormParent
INNER JOIN ResponseForm
ON ResponseFormParent.ResponseFormParentId = ResponseForm.ResponseFormParentId
WHERE ResponseForm.RegistrationDeadline >= '5/1/2009'
Run Code Online (Sandbox Code Playgroud)
ResponseFormParent有3个整数,1个日期时间和1个nvarchar(50).ResponseForm有4个整数,1个日期时间,1个位和1个nvarchar(255).
是什么导致了这个问题?这个错误没有意义.
更新:调用查询的代码
public DataSet ExecuteQuery(string sql)
{
DataSet ds = null;
try
{
using (SqlConnection dbconn = new SqlConnection(connectionString))
using (SqlCommand dbcmd = new SqlCommand(sql, dbconn))
{
SqlDataAdapter dbadapter = new SqlDataAdapter(dbcmd);
ds = new DataSet();
dbadapter.Fill(ds);
}
}
catch (Exception ex)
{
Utility.LogError(sql, ex);
}
return ds;
}
Run Code Online (Sandbox Code Playgroud)
您可能正在查询两个不同的数据库.您是否在应用程序中检查了Connection,以确保您实际查询的是在SQL Mgmt Studio中查询的数据库?您也可能指向不同的服务器.您可能还想在Connection中检查它.
如果是这种情况,那么很可能是您要查询的两个数据库之间的数据库模式不匹配.