I have a function like this
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();
}
On debugging, it is giving the result till the connection is open but the var Reader is not reading the data.
Can anybody point out where the error is!!
Is your provided code the same you run?
Strange behaviour of ‘working’ in debug, but not in runtime, usually happens if you have self initializing get properties. Something like this:
So if you use _name directly and debugger displays such a property, it ‘accidentally’ initializes your property before use.