【发布时间】:2010-12-10 11:32:42
【问题描述】:
我有这样的功能
try
{
using(var sConnection = new SqlConnection(ConnectionString))
using(var sCommand = sConnection.CreateCommand())
{
sCommand.CommandText = @"SELECT
TABLE_NAME
AS
TABLES
FROM
INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE
CONSTRAINT_TYPE = 'PRIMARY KEY'
AND
TABLE_NAME <> 'dtProperties'
ORDER BY
TABLE_NAME";
sConnection.Open();
using(var reader = sCommand.ExecuteReader()) // Troublesome line
{
while(reader.Read())
{
sb.AppendLine(reader.GetString(0));
}
}
}
}
catch(Exception ex)
{
//All the exceptions are handled and written in the EventLog.
EventLog log = new EventLog("Application");
log.Source = "MFDBAnalyser";
log.WriteEntry(ex.Message);
}
return sb.ToString();
}
在调试时,它会给出结果,直到连接打开但 var Reader 没有读取数据。
谁能指出错误在哪里!!
【问题讨论】:
-
你的意思是它毫无例外地执行,但没有给出数据? SQL Profiler 显示了什么?
-
您能否详细说明您遇到的异常情况
-
谁能告诉我为什么会这样。
-
你有“var reader”而不是“SQLDataReader reader”的原因吗?
-
改变我也看到了..它对我也不起作用!1