[InvalidOperationException: Invalid operation. The connection is closed.]
System.Data.SqlClient.SqlConnection.GetOpenConnection() +2417814
System.Data.SqlClient.SqlConnection.get_ServerVersion() +9
我在序列化对象时收到此错误。
public string SerializeObj(TemplateData obj)
{
string data = null;
try
{
JavaScriptSerializer js = new JavaScriptSerializer();
** data = js.Serialize(obj); [This is what i am finding issue is][1]**
}
catch (InvalidOperationException iopException)
{
string exception = iopException.Data.ToString();
return exception;
}
return data;
请注意:当我序列化我的对象时,我没有使用数据库连接。
有人可以建议我如何解决这个问题吗?
当我序列化我的对象时,它将我的类名为TemplateData。
public List<TemplateData> List(string myKey)
{
TemplateBusinessLogic businessLogic = new TemplateBusinessLogic();
TemplateData templateData = new TemplateData();
templateData.key = myKey;
string postKey = businessLogic.SerializeObj(templateData);
string listUrl = MandrillAutomation.Helper.Config.ConfigManager.ConstantsConfig.GetValue("listUrl");
string requestContent = HttpRequestUrl(listUrl, "POST", postKey);
List<TemplateData> listContent = businessLogic.DeserializeObj<List<TemplateData>>(requestContent); // DESERIALIZE OBJECT
for (int i = 0; i <= listContent.Count-1; i++)
{
FileHelper fileHelp = new FileHelper();
fileHelp.SaveTemplate(listContent[i].name, listContent[i].code);
}
//SaveTemplate(listContent); //Save Templates into desire format
log.Info(listContent.Count + " Templates avilable" );
log.Info("[ ");
log.Info("Templates :" + GetTemplateName(listContent));
log.Info(" ]");
foreach (var content in listContent)
{
log.Info("Name of Template : " + content.name + " || Slug of Template : " + content.slug + " || in Account : " + myKey);
}
return listContent;
}
我有类TemplateData,如下所示:
public class TemplateData :DbContext
{
public string key {get; set;}
public string name { get; set; }
public string slug { get; set; }
public string fromEmail { get; set; }
public string fromName { get; set; }
public string subject { get; set; }
public string code { get; set; }
public string text { get; set; }
public string publish { get; set; }
public string[] labels { get; set; }
public string created_at{ get; set; }
public string updated_at { get; set; }
}
答案 0 :(得分:1)
我只是从我的DbContext
课程中删除了TemplateData
。
现在没有错误。 :)