Monday, December 29, 2014

Sql Server 2008 R2 keeps disconnecting after a few minutes -- how can I prevent this?

Check if you have Auto-close option enabled for the DB, if so, disable it.


Satish Kartan www.sqlfood.com


Sql Server 2008 R2 keeps disconnecting after a few minutes -- how can I prevent this?

That is not supposed to happen.


We would need more information about this disconnects. How do notice them? Do you get an error message at some point?


What does this query return?


SELECT connectionproperty('Net_transport')


I seem to recall that SSMS 2008 R2 has some irritating quirks; I have mainly stayed away from it. Maybe this is something that strikes? You could download SSMS 2012 from

http://www.microsoft.com/en-us/download/details.aspx?id=29062

(When you click download you get a list of options, select the one with Management Studio.)


And why SSMS 2012 and not SSMS 2014? Because SSMS 2014 has some new (very) irritating quirks.





Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Sql Server 2008 R2 keeps disconnecting after a few minutes -- how can I prevent this?

I agree with Erland there can be many reasons. How about Antivirus running on the system. Antivirus has this nature of disconnecting sessions. There are lot of options provided check which applied in your case.




Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it



My Technet Wiki Article


MVP


Sql Server 2008 R2 keeps disconnecting after a few minutes -- how can I prevent this?

Rich P123, I did ask you about the Power option in my earlier thread. Because, I had the same issue sometimes back, And when I changed the options, the issue did not re-occur. So, you may try the same and let us know how it works for you.


Go to Control Panel --> Hardware --> Power Options --> Make sure high performance is selected --> Change When Computer Sleeps --> Change Advanced Power Settings --> Expand Hard Disk Node from the tree view --> Select "Never" for turn off hard disks after option


Sql Server 2008 R2 keeps disconnecting after a few minutes -- how can I prevent this?

The hard disks should have nothing to do with it. I just checked my machine, and I have set the hard disks to be turned off after 20 minutes, and I never have the problem that Rich describes. True, I am not running SSMS 2008 R2, but the hard disks have nothing to due with the communication between SSMS and SQL Server. I do have the Sleep setting set to Never.


I think that as long as Rich works on the machine, the connection to SQL Server should stay alive.


I think it is worth checking the SQL Server errorlog when this happens. Is there a dump or some other message indicating that the connection has been lost? Also, check when SQL Server started - maybe something/someone restarts SQL Server? Furthermore, check the autoclose setting for the database.





Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

how to add a method or region in end of a class with parse cs file

hello


i wanna read a cs file and add a method or region in end of a class .


this operation is located in a visual studio add-in project (extensibility project).


cs file sample:



using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using Tools.Cmn;
using Common.Cmn;
namespace Life.Cmn
{
[Serializable]
[LocalCache(false)]
[Table(BaseTableName = "lf.Config", TableName = "lf.Config")]
public partial class LifeConfig : CommonConfig
{
public LifeConfig()
{
}

public LifeConfig(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

[Association(OtherKey = "Subject,Name", ThisKey = "Subject,Name")]
public EntityList<LifeConfigHistory> LifeConfigHistoryList
{
get { return GetNavChildList<LifeConfigHistory>("LifeConfigHistoryList"); }
}

}
}

and i want add below code in end of class:



#region UniversalLifePrm

public static T UniversalLifePrm<T>(string configName)
{
return LifeCmn.GetConfigVal("UniversalLifePrm", configName, default(T));
}

#endregion



in finally my class will be this:



using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using Tools.Cmn;
using Common.Cmn;
namespace Life.Cmn
{
[Serializable]
[LocalCache(false)]
[Table(BaseTableName = "lf.Config", TableName = "lf.Config")]
public partial class LifeConfig : CommonConfig
{
public LifeConfig()
{
}

public LifeConfig(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

[Association(OtherKey = "Subject,Name", ThisKey = "Subject,Name")]
public EntityList<LifeConfigHistory> LifeConfigHistoryList
{
get { return GetNavChildList<LifeConfigHistory>("LifeConfigHistoryList"); }
}

#region UniversalLifePrm

public static T UniversalLifePrm<T>(string configName)
{
return LifeCmn.GetConfigVal("UniversalLifePrm", configName, default(T));
}

#endregion

}
}

please help me.


thanks.


how to add a method or region in end of a class with parse cs file

On the other hand, if you're writing a quick and dirty utility to update a bunch of your .cs files, then you can do it like this (as long as you realize that all of the projects that have a file that you've modified will need to be recompiled after you're done).



  1. Read the .cs file in using File.ReadLines()

  2. Turn the array into a List and Insert your text

  3. Write the file back using File.WriteAllLines().



string[] lines = File.ReadAllLines(FileName);
List<string> lineList = lines.ToList();

int insertPos = lineList.Count - 2;
lineList.Insert(insertPos++, " #region UniversalLifePrm");
lineList.Insert(insertPos++, " public static T UniversalLifePrm<T>(string configName)");
lineList.Insert(insertPos++, "// Put the rest of your code here.");
lineList.Insert(insertPos, " #endregion");

File.WriteAllLines(FileName, lineList.ToArray());





~~Bonnie DeWitt [C# MVP]


http://geek-goddess-bonnie.blogspot.com