Click here to Skip to main content
15,896,493 members
Home / Discussions / Database
   

Database

 
GeneralRe: Get SQL server Name Pin
sunil goyalG25-Jul-08 23:56
sunil goyalG25-Jul-08 23:56 
GeneralRe: Get SQL server Name Pin
BhadeliaImran26-Jul-08 1:39
BhadeliaImran26-Jul-08 1:39 
GeneralRe: Get SQL server Name Pin
Paul Conrad26-Jul-08 14:58
professionalPaul Conrad26-Jul-08 14:58 
GeneralRe: Get SQL server Name Pin
Mycroft Holmes26-Jul-08 15:04
professionalMycroft Holmes26-Jul-08 15:04 
GeneralRe: Get SQL server Name Pin
Paul Conrad26-Jul-08 15:06
professionalPaul Conrad26-Jul-08 15:06 
GeneralRe: Get SQL server Name Pin
Mycroft Holmes26-Jul-08 15:19
professionalMycroft Holmes26-Jul-08 15:19 
AnswerRe: Get SQL server Name [modified] Pin
Paul Conrad26-Jul-08 15:00
professionalPaul Conrad26-Jul-08 15:00 
QuestionSelect Row with column name Pin
Member 400849225-Jul-08 21:29
Member 400849225-Jul-08 21:29 
AnswerRe: Select Row with column name Pin
Vimalsoft(Pty) Ltd26-Jul-08 12:23
professionalVimalsoft(Pty) Ltd26-Jul-08 12:23 
QuestionShould I use SQL Server as backend for huge charting application? Pin
mahabir25-Jul-08 19:17
mahabir25-Jul-08 19:17 
AnswerRe: Should I use SQL Server as backend for huge charting application? Pin
Mycroft Holmes25-Jul-08 23:01
professionalMycroft Holmes25-Jul-08 23:01 
GeneralRe: Should I use SQL Server as backend for huge charting application? Pin
mahabir26-Jul-08 17:50
mahabir26-Jul-08 17:50 
GeneralRe: Should I use SQL Server as backend for huge charting application? Pin
Mycroft Holmes26-Jul-08 21:28
professionalMycroft Holmes26-Jul-08 21:28 
QuestionADO Excel problem Pin
followait25-Jul-08 16:36
followait25-Jul-08 16:36 
AnswerRe: ADO Excel problem Pin
Mycroft Holmes25-Jul-08 23:05
professionalMycroft Holmes25-Jul-08 23:05 
GeneralRe: ADO Excel problem Pin
followait26-Jul-08 6:07
followait26-Jul-08 6:07 
GeneralRe: ADO Excel problem Pin
Mycroft Holmes26-Jul-08 14:17
professionalMycroft Holmes26-Jul-08 14:17 
QuestionLINQ to SQL and TransactionScope == DTC Pin
Mark J. Miller25-Jul-08 12:33
Mark J. Miller25-Jul-08 12:33 
AnswerRe: LINQ to SQL and TransactionScope == DTC Pin
Mark J. Miller28-Jul-08 10:18
Mark J. Miller28-Jul-08 10:18 
Ok, well I came up with a solution for this (for anyone interested).

The DataContext is not aware of any other contexts (through thread local storage) in any way. So I basically decided to use thread local storage to store my DataContext for the current thread (HttpRequest).

Here's how it works. The DataContext classes generated for a dbml file is a partial class, so I added a class file to the same project which contains a static factory method, GetDataContext(). GetDataContext checks HttpContext.Current.Items to see if a DataContext object already exists. If not, it creates and new one, stores it in HttpContext.Current.Items and the returns the new instance. If the object already exists, it just returns the existing object to the caller.

<br />
public static DataContext GetDataContext()<br />
{<br />
  if(HttpContext.Current == null)<br />
    return new DataContext(connectionString);<br />
<br />
  if(HttpContext.Current.Items.Contains("DataContext"))<br />
  {<br />
    return (DataContext) HttpContext.Current.Items["DataContext"];<br />
  }<br />
<br />
  return new DataContext(connectionString);<br />
}<br />


Now, I am able to use TransactionScope to wrap my business logic without having to use DataContext directly. Plus there are other benefits, my Save method no longer requires the additional database call to retrieve the record and copy the changes before calling SubmitChanges(). So compared with my previous post, my Save method now looks like this:

<br />
        public static Step Save(Step step)<br />
        {<br />
		KRATDataContext context = KRATDataContext.GetDataContext();<br />
<br />
		if ( step.StepID <= 0 )<br />
		{<br />
			context.Steps.InsertOnSubmit( step );<br />
		}<br />
<br />
		context.SubmitChanges();<br />
<br />
		return step;<br />
	}<br />


Which requires one less database call, always a plus Cool | :cool: . This all solves my Transaction problem because it uses the same connection object (because we're using the same DataContext which owns the Connection object) and so there is no longer any distributed transactions (DTC) required.

Code responsibly: OWASP.org
Mark's blog: developMENTALmadness.blogspot.com

QuestionDatabase column Pin
Verghese25-Jul-08 9:10
Verghese25-Jul-08 9:10 
AnswerRe: Database column Pin
Blue_Boy25-Jul-08 11:59
Blue_Boy25-Jul-08 11:59 
QuestionCrystal Report Title @ Run Time Pin
Verghese25-Jul-08 5:33
Verghese25-Jul-08 5:33 
AnswerRe: Crystal Report Title @ Run Time Pin
SomeGuyThatIsMe25-Jul-08 5:52
SomeGuyThatIsMe25-Jul-08 5:52 
AnswerRe: Crystal Report Title Pin
David Mujica25-Jul-08 6:32
David Mujica25-Jul-08 6:32 
GeneralRe: Crystal Report Title Pin
Verghese25-Jul-08 9:17
Verghese25-Jul-08 9:17 

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.