Monday, March 19, 2012

Fatal Error 682 and SqlCacheDependency

Hello,

I have tried two ways for executing a query and creating a dependency
on it, one using plain Sql commands, the other using Enterprise
Library wrapped commands.

I keep getting:

Warning: Fatal error 682 occurred at Oct 12 2007 11:01AM. Note the
error and time, and contact your system administrator.

string xml = cmd.ExecuteScalar() as string;

When I execute it. Does anyone know what could cause this.

I have read both of these posts and have not yet been able to
investigate the SQL machine's event viewer though:

http://forums.asp.net/p/959871/1188606.aspx#1188606

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1203630&SiteID=1

The "value" column is an XML datatype field.

Thanks,
Josh

public static ContentXmlUtilResult GetContentXml(
string key,
bool createDependency)
{
ContentXmlUtilResult result = new ContentXmlUtilResult();

string connString = Global.Current.ConnectionString;

using (SqlConnection conn =
new SqlConnection(connString))
{
SqlCommand cmd =
new SqlCommand(
"SELECT Value FROM dbo.ContentXml WHERE [Key]
= '" + key + "'",
conn);

if (createDependency)
{
System.Web.Caching.SqlCacheDependency dependency =
new SqlCacheDependency(cmd);

result.Dependency = dependency;
}

conn.Open();

string xml = cmd.ExecuteScalar() as string;

conn.Close();

result.Content = xml;
}

return result;

//SqlCommand cmd = (SqlCommand)
// Global.Current.Database.GetSqlStringCommand(
// //@."SELECT Value FROM dbo.ContentXml WHERE [Key] =
@.Key");
// @."SELECT Value FROM dbo.ContentXml WHERE [Key] = '"
+ key + "'");

////cmd.Parameters.Add("@.Key", SqlDbType.VarChar).Value =
key;

//if (createDependency)
//{
// System.Web.Caching.SqlCacheDependency dependency =
// new System.Web.Caching.SqlCacheDependency(cmd);

// result.Dependency = dependency;
//}

//string xml = Global.Current.Database.ExecuteScalar(cmd)
as string;

//result.Content = xml;

//return result;
}

However bizarre this may sound, I solved this problem by changing the length of the key to 15 charcters. I was using SystemStatusContent as the value, so the SQL statement was:

SELECT Value FROM dbo.ContentXml WHERE [Key] = 'SystemStatusContent'

But, when I changed the key to a smaller value, it now works fine!

SELECT Value FROM dbo.ContentXml WHERE [Key] = 'SystemStatus'

I do not know why this fixed it. I'm just glad it did.

Josh

No comments:

Post a Comment