CommandTimeout似乎没有效果查询在30秒后仍然超时(CommandTimeout seems to have no effect Queries still timing out after 30 seconds)
我们的生产数据库增长到一个大小,其中我们的几个较长时间运行的存储过程花费的时间超过了默认的30秒完成时间。 我已经以编程方式在命令对象上设置了一些CommandTimeouts,但是对存储过程的调用仍然显示在30秒后超时。
这是我做的:
在web.config中设置此属性
add key =“CommandTimeOut”value =“180”
将此添加到我的类的顶部,需要超时设置:
Dim COMMAND_TIMEOUT As Integer = ConfigurationManager.AppSettings(“CommandTimeOut”)
创建命令对象后,在对象上设置超时属性。
cmd.CommandTimeout = COMMAND_TIMEOUT
不幸的是,当执行时间超过30秒时,我的存储过程似乎仍然超时。 任何帮助将不胜感激。
Our production database as grown to a size where several of our longer running stored procedures are taking more than the default 30 seconds to complete. I've programatically set some of the CommandTimeouts on the command objects but the calls to the store procedures still appear to be timing out after 30 seconds.
Here's what I did:
In web.config set this property
add key="CommandTimeOut" value="180"
Added this to the top of my class that needs the timeout set:
Dim COMMAND_TIMEOUT As Integer = ConfigurationManager.AppSettings("CommandTimeOut")
After creating the command object set the timeout property on the object.
cmd.CommandTimeout = COMMAND_TIMEOUT
Unfortunately my stored procedures still seem to be timing out when they take longer than 30 seconds to execute. Any help would be greatly appreciated.
原文:https://stackoverflow.com/questions/7355736
最满意答案
有很多方法可以解决这个问题,因为你提到你想要等效的
C#
实体,我更喜欢这种方法。为您的xml生成C#实体(有很多工具)
[XmlRoot(ElementName="VISUALFOLDER")] public class VISUALFOLDER { [XmlAttribute(AttributeName="Date")] public string Date { get; set; } [XmlAttribute(AttributeName="ByUser")] public string ByUser { get; set; } [XmlAttribute(AttributeName="Name")] public string Name { get; set; } [XmlAttribute(AttributeName="Type")] public string Type { get; set; } [XmlAttribute(AttributeName="StartView")] public string StartView { get; set; } [XmlAttribute(AttributeName="ScreenOffset")] public string ScreenOffset { get; set; } } [XmlRoot(ElementName="VISUALTABSHEET")] public class VISUALTABSHEET { [XmlAttribute(AttributeName="Date")] public string Date { get; set; } [XmlAttribute(AttributeName="Name")] public string Name { get; set; } [XmlAttribute(AttributeName="Type")] public string Type { get; set; } } [XmlRoot(ElementName="VISUALINDEXFIELD")] public class VISUALINDEXFIELD { [XmlAttribute(AttributeName="Date")] public string Date { get; set; } [XmlAttribute(AttributeName="Name")] public string Name { get; set; } } [XmlRoot(ElementName="INDEXFIELD")] public class INDEXFIELD { [XmlElement(ElementName="VISUALINDEXFIELD")] public VISUALINDEXFIELD VISUALINDEXFIELD { get; set; } [XmlAttribute(AttributeName="Date")] public string Date { get; set; } [XmlAttribute(AttributeName="Name")] public string Name { get; set; } } [XmlRoot(ElementName="TABSHEET")] public class TABSHEET { [XmlElement(ElementName="VISUALTABSHEET")] public VISUALTABSHEET VISUALTABSHEET { get; set; } [XmlElement(ElementName="INDEXFIELD")] public List<INDEXFIELD> INDEXFIELD { get; set; } [XmlAttribute(AttributeName="Date")] public string Date { get; set; } [XmlAttribute(AttributeName="Name")] public string Name { get; set; } [XmlAttribute(AttributeName="Type")] public string Type { get; set; } [XmlElement(ElementName="DOCUMENT")] public List<DOCUMENT> DOCUMENT { get; set; } [XmlAttribute(AttributeName="Data")] public string Data { get; set; } [XmlAttribute(AttributeName="SeqNo")] public string SeqNo { get; set; } [XmlAttribute(AttributeName="Title")] public string Title { get; set; } [XmlAttribute(AttributeName="Password")] public string Password { get; set; } } [XmlRoot(ElementName="VISUALDOCUMENT")] public class VISUALDOCUMENT { [XmlAttribute(AttributeName="Date")] public string Date { get; set; } [XmlAttribute(AttributeName="Name")] public string Name { get; set; } [XmlAttribute(AttributeName="Type")] public string Type { get; set; } [XmlAttribute(AttributeName="Height")] public string Height { get; set; } [XmlAttribute(AttributeName="Width")] public string Width { get; set; } } [XmlRoot(ElementName="DOCUMENT")] public class DOCUMENT { [XmlElement(ElementName="VISUALDOCUMENT")] public VISUALDOCUMENT VISUALDOCUMENT { get; set; } [XmlAttribute(AttributeName="Date")] public string Date { get; set; } [XmlAttribute(AttributeName="Name")] public string Name { get; set; } [XmlAttribute(AttributeName="Type")] public string Type { get; set; } [XmlAttribute(AttributeName="Data")] public string Data { get; set; } [XmlAttribute(AttributeName="FileName")] public string FileName { get; set; } [XmlAttribute(AttributeName="FileOffset")] public string FileOffset { get; set; } [XmlAttribute(AttributeName="FileSize")] public string FileSize { get; set; } [XmlAttribute(AttributeName="BinaryType")] public string BinaryType { get; set; } } [XmlRoot(ElementName="FOLDER")] public class FOLDER { [XmlElement(ElementName="VISUALFOLDER")] public VISUALFOLDER VISUALFOLDER { get; set; } [XmlElement(ElementName="TABSHEET")] public List<TABSHEET> TABSHEET { get; set; } [XmlAttribute(AttributeName="Date")] public string Date { get; set; } [XmlAttribute(AttributeName="ByUser")] public string ByUser { get; set; } [XmlAttribute(AttributeName="Name")] public string Name { get; set; } [XmlAttribute(AttributeName="Type")] public string Type { get; set; } [XmlAttribute(AttributeName="MemberOf")] public string MemberOf { get; set; } } [XmlRoot(ElementName="FOLDERS")] public class FOLDERS { [XmlElement(ElementName="FOLDER")] public List<FOLDER> FOLDER { get; set; } [XmlAttribute(AttributeName="Name")] public string Name { get; set; } }
现在我们可以使用下面的代码片段对此进行反序列化。
StreamReader reader = new StreamReader(filepath); var folders = (FOLDERS)serializer.Deserialize(reader);
工作
Demo
I came up with the following solution:
file is a class where I save all data of a file.
var elements = xdoc.Element("FOLDERS"); if (elements == null) { throw new KeyNotFoundException(); } var data = elements .Elements("FOLDER") .Where(xml => xml .Elements("TABSHEET") .Elements("DOCUMENT") .Select(x => x.Attribute("FileName").Value) .ToList() .Contains(file.FileName) ) .Select(xml => xml .Elements("TABSHEET") .Elements("INDEXFIELD") .Where(x => x.Attribute("Name").Value == "Date" || x.Attribute("Name").Value == "Note" ) .Select(x => new string[] { (string)x.Attribute("Name"), (string)x.Value })) .ToList(); if (data.Count != 1) { file.Upload = false; continue; } var dataDictionary = data[0].ToDictionary(item => item[0], item => item[1]); file.Date = !dataDictionary.ContainsKey("Date") || string.IsNullOrWhiteSpace(dataDictionary["Date"]) ? new DateTime() : DateTime.Parse(dataDictionary["Date"]);
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
使用Linq C#使用特定属性查询特定xml标记的值(Querying value from a specific xml tag with a specific attribute using Linq C#)[2021-10-09]
t.Attributes("class")永远不会返回null。 t.Attribute("class")使用t.Attribute("class") (或.Where(t => t.Attributes("class").Any()) )。 你不需要t.Element("input") var selected = xmlDoc.Descendants("input") .Where(t => t.Attribute("class") != null) ... -
Select()回调中的a是
元素。 a.Element("Artist")不是什么。 a in your Select() callback is the element. a.Element("Artist") isn't anything. -
目前,您正在尝试获取文档中每个元素的user属性的值 - 例如,包括根元素。 这里有两个选项,我可能会同时使用它们: 使用xdoc.Descendants("user")指定您只需要user元素 使用XAttribute来代替Value属性; 这样,如果没有这样的属性,演员也将返回null 此外,如果找不到匹配元素,则使用FirstOrDefault因此您将获得null值 - 但无论如何您都尝试设置属性值。 不要那样做。 所以,把它们放在一起 - 并通过使用带有谓词的FirstOrDefault的重载来Fi ...
-
如何使用linq从c#中的xml元素添加自定义属性值?(How to add the custom attributes value from xml element in c# using linq?)[2022-07-04]
你可以试试这个: var directory = xdoc.DescendantsAndSelf("task") .Select(c => new { Path = c.Elements("directory").Attributes("path").First().Value, Day = c.Elements("days").Attributes(" ... -
两个错误: 1.) keyMaterial不是keyMaterial的直接子WLANProfile ,这就是为什么你没有得到任何结果(c.Elements只会寻找直接的孩子) 2.)您需要在XML中使用指定的命名空间 - 否则没有节点匹配 两者均适用: XNamespace xns = "http://www.microsoft.com/networking/WLAN/profile/v1"; var networkKey = (from c in doc.Descendants(xns + "keyMat ...
-
是的 - 你只是错过了命名空间: string desiredId = "4bd7b5ac-cb29-4d34-97be-deaebe4a5186"; XNamespace ns = "http://schemas.datacontract.org/2004/07/Stuff"; var pbp = (from b in data.Descendants(ns + "Item") where b.Element(ns + "Id").Value == desiredId ...
-
Linq to XML(C#)解析没有属性/ id到对象的XML树(Linq to XML (C#) parse XML tree with no attributes/id to object)[2022-03-24]
您可以使用此代码: XDocument file = XDocument.Parse(xml); var persons = file.Descendants("rows") .Select (x => { var person = new Person(); var values = x.Descendants("row") .Group ... -
有很多方法可以解决这个问题,因为你提到你想要等效的C#实体,我更喜欢这种方法。 为您的xml生成C#实体(有很多工具) [XmlRoot(ElementName="VISUALFOLDER")] public class VISUALFOLDER { [XmlAttribute(AttributeName="Date")] public string Date { get; set; } [XmlAttribute(AttributeName="ByUser")] publi ...