Click here to Skip to main content
15,895,084 members
Home / Discussions / C#
   

C#

 
QuestionHow to get path to public directory Pin
CTaylor8919-Feb-10 9:06
CTaylor8919-Feb-10 9:06 
AnswerRe: How to get path to public directory Pin
Dave Kreskowiak19-Feb-10 9:40
mveDave Kreskowiak19-Feb-10 9:40 
GeneralRe: How to get path to public directory Pin
CTaylor8919-Feb-10 10:50
CTaylor8919-Feb-10 10:50 
QuestionProgram in Client side is not working Pin
Said Ali Jalali19-Feb-10 8:12
Said Ali Jalali19-Feb-10 8:12 
AnswerRe: Program in Client side is not working Pin
Paulo Zemek19-Feb-10 10:24
mvaPaulo Zemek19-Feb-10 10:24 
GeneralRe: Program in Client side is not working Pin
Said Ali Jalali20-Feb-10 5:12
Said Ali Jalali20-Feb-10 5:12 
GeneralRe: Program in Client side is not working Pin
Paulo Zemek20-Feb-10 5:24
mvaPaulo Zemek20-Feb-10 5:24 
QuestionDesign Question for DataReader error Pin
galacticvoid19-Feb-10 7:04
galacticvoid19-Feb-10 7:04 
Ok, let me start off by saying that this is my first post ever, so be gentle.

I am having an issue with a web service where I am randomly getting the following error:

System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.

The error stems from the same object all of the time. So after investigating the issue I believe it is happening because I am using a static TableAdapter for one particular sql server database table. This is a surrogates table which is used to track keys to all of the other tables within the database (Not my design and I cannot change it). Cry | :((

Here is my question:

Would it be better to implement the static TableAdapter and lock that or to create a generic object to lock and create a new TableAdapter every time I would like a new key. This Surrogate table has roughly 30 different tables that it manages keys for and it probably will create between 100 and 200 keys per call. So creating a TableAdapter every time that method is called seems like wasted resources but I am not sure if having a static TableAdapter is the best way to go either. Also, any better way to handle it would be greatly appreciated.

Example Code:

This Way
public class SurrogateClass
{
	public SurrogateClass(){}

	private static SurrogateTableAdapter SurrogateAdapter = new SurrogateTableAdapter();

	public static int GetSurrogateByTableName(String tableName)
	{
		int result = 0;
		lock (SurrogateAdapter)
		{
			SurrogateRow row = SurrogateAdapter.GetSurrogateByTableName(tableName).FindByTABLENAME(tableName);
			if (row != null)
			{
				int.TryParse(row.SURROGATE.ToString(), out result);
				result += 1;
				row.SURROGATE = result;
				SurrogateAdapter.Update(row);
			}
			else
			{
				result = -1;
			}
		}
		return result;
	}
}


Or this way
public class SurrogateClass
{
	public SurrogateClass(){}

	private static object lockerOjbect = new object;

	public static int GetSurrogateByTableName(String tableName)
	{
		int result = 0;
		lock (lockerObject)
		{
			using (SurrogateTableAdapter SurrogateAdapter = new SurrogateTableAdapter())
			{
				SurrogateRow row = SurrogateAdapter.GetSurrogateByTableName(tableName).FindByTABLENAME(tableName);
				if (row != null)
				{
					int.TryParse(row.SURROGATE.ToString(), out result);
					result += 1;
					row.SURROGATE = result;
					SurrogateAdapter.Update(row);
				}
				else
				{
					result = -1;
				}
			}
		}
		return result;
	}
}

AnswerRe: Design Question for DataReader error Pin
PIEBALDconsult19-Feb-10 17:55
mvePIEBALDconsult19-Feb-10 17:55 
GeneralRe: Design Question for DataReader error Pin
galacticvoid22-Feb-10 4:30
galacticvoid22-Feb-10 4:30 
Questioncollapsible panel in c sharp? Pin
Pawan Kiran19-Feb-10 6:33
Pawan Kiran19-Feb-10 6:33 
AnswerRe: collapsible panel in c sharp? Pin
Not Active19-Feb-10 7:14
mentorNot Active19-Feb-10 7:14 
QuestionTimer Control [modified] Pin
dalila y19-Feb-10 5:20
dalila y19-Feb-10 5:20 
AnswerRe: Timer Control Pin
Not Active19-Feb-10 5:37
mentorNot Active19-Feb-10 5:37 
GeneralRe: Timer Control Pin
dalila y19-Feb-10 5:49
dalila y19-Feb-10 5:49 
GeneralRe: Timer Control Pin
Pete O'Hanlon19-Feb-10 6:11
mvePete O'Hanlon19-Feb-10 6:11 
GeneralRe: Timer Control Pin
dalila y19-Feb-10 18:54
dalila y19-Feb-10 18:54 
QuestionRetrieve IP Address and compare with database Pin
dalila y19-Feb-10 5:13
dalila y19-Feb-10 5:13 
AnswerRe: Retrieve IP Address and compare with database Pin
PIEBALDconsult19-Feb-10 6:42
mvePIEBALDconsult19-Feb-10 6:42 
GeneralRe: Retrieve IP Address and compare with database Pin
dalila y19-Feb-10 16:24
dalila y19-Feb-10 16:24 
GeneralRe: Retrieve IP Address and compare with database Pin
PIEBALDconsult19-Feb-10 17:40
mvePIEBALDconsult19-Feb-10 17:40 
Questionhow can i kill a protected process?? [modified] or a SYSTEM process ?? Pin
andyxfun19-Feb-10 4:46
andyxfun19-Feb-10 4:46 
AnswerRe: how can i kill a protected process?? [modified] or a SYSTEM process ?? Pin
Dave Kreskowiak19-Feb-10 9:28
mveDave Kreskowiak19-Feb-10 9:28 
QuestionNeed a class that will implemnt strings Pin
joejack22219-Feb-10 4:35
joejack22219-Feb-10 4:35 
AnswerRe: Need a class that will implemnt strings Pin
OriginalGriff19-Feb-10 4:56
mveOriginalGriff19-Feb-10 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.