Click here to Skip to main content
15,904,155 members
Home / Discussions / Database
   

Database

 
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 
AnswerRe: Crystal Report Title @ Run Time Pin
Wendelius25-Jul-08 10:17
mentorWendelius25-Jul-08 10:17 
QuestionDynamic Database Creation ?? Pin
C. L. Phillip25-Jul-08 4:13
C. L. Phillip25-Jul-08 4:13 
AnswerRe: Dynamic Database Creation ?? Pin
TheFM23425-Jul-08 4:42
TheFM23425-Jul-08 4:42 
GeneralRe: Dynamic Database Creation ?? Pin
C. L. Phillip25-Jul-08 4:49
C. L. Phillip25-Jul-08 4:49 
AnswerRe: Dynamic Database Creation ?? Pin
TheFM23425-Jul-08 5:14
TheFM23425-Jul-08 5:14 
GeneralRe: Dynamic Database Creation ?? Pin
C. L. Phillip25-Jul-08 5:23
C. L. Phillip25-Jul-08 5:23 
GeneralRe: Dynamic Database Creation ?? Pin
BhadeliaImran26-Jul-08 1:53
BhadeliaImran26-Jul-08 1:53 
AnswerRe: Dynamic Database Creation ?? Pin
Wendelius25-Jul-08 9:53
mentorWendelius25-Jul-08 9:53 
AnswerRe: Dynamic Database Creation ?? Pin
Mycroft Holmes25-Jul-08 22:39
professionalMycroft Holmes25-Jul-08 22:39 
GeneralRe: Dynamic Database Creation ?? Pin
C. L. Phillip27-Jul-08 5:41
C. L. Phillip27-Jul-08 5:41 
QuestionSqlserver datatabase deployment along with setup file Pin
vishnukamath25-Jul-08 1:45
vishnukamath25-Jul-08 1:45 

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.