5 Replies - 409 Views - Last Post: 14 August 2011 - 11:53 PM Rate Topic: -----

#1 The Architect 2.0  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 351
  • Joined: 22-May 08

Using a Model class around a SQL Database

Posted 13 August 2011 - 07:06 PM

I'm wondering about the 'dangers' of keeping a database stream open.

currently, i'm using a 'using' statement to keep my database stream open as necessary. BUT, i want to wrap my database up into a Model class and call 'CRUD' methods on the model to get work done.

i'm just wondering when i should open the stream to the database:
1) when i create an object from the model class
2) everytime i call a method

i'll be accessing the database approximately every 20 seconds to add a handful of itecs.

also, i have some rather complex operations to do, but should i just use 1) and keep the set of operations simple? or just a new method for each complex operation?

i'm calling a SQLCE database if that matters

Is This A Good Question/Topic? 0
  • +

Replies To: Using a Model class around a SQL Database

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Using a Model class around a SQL Database

Posted 13 August 2011 - 10:20 PM

Doesn't matter. When you first make a connection to the database, the .NET library makes multiple connections (referred to as the connection pool) and keeps these connections open until your program ends. This speeds up later connections as it just pulls one from the pool and when you close the connection it returns it to the pool.

You can read about it here: SQL Server Connection Pooling (ADO.NET)
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Using a Model class around a SQL Database

Posted 14 August 2011 - 06:56 AM

View PostMomerath, on 14 August 2011 - 01:20 AM, said:

Doesn't matter. When you first make a connection to the database, the .NET library makes multiple connections (referred to as the connection pool) and keeps these connections open until your program ends. This speeds up later connections as it just pulls one from the pool and when you close the connection it returns it to the pool.

You can read about it here: SQL Server Connection Pooling (ADO.NET)


Well, it does matter since he is using SQLCE, which doesn't support connection pooling. You SHOULD leave the connection open as long as possible with SQLCE.

http://blogs.msdn.co.../21/431074.aspx
http://csharponphone...and-thread.html
Was This Post Helpful? 1
  • +
  • -

#4 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Using a Model class around a SQL Database

Posted 14 August 2011 - 01:06 PM

View Posteclipsed4utoo, on 14 August 2011 - 06:56 AM, said:

Well, it does matter since he is using SQLCE, which doesn't support connection pooling. You SHOULD leave the connection open as long as possible with SQLCE.

http://blogs.msdn.co.../21/431074.aspx
http://csharponphone...and-thread.html

That's the mobile edition and using SqlCeConnection.

This post has been edited by Momerath: 14 August 2011 - 01:06 PM

Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Using a Model class around a SQL Database

Posted 14 August 2011 - 07:14 PM

View PostMomerath, on 14 August 2011 - 04:06 PM, said:

View Posteclipsed4utoo, on 14 August 2011 - 06:56 AM, said:

Well, it does matter since he is using SQLCE, which doesn't support connection pooling. You SHOULD leave the connection open as long as possible with SQLCE.

http://blogs.msdn.co.../21/431074.aspx
http://csharponphone...and-thread.html

That's the mobile edition and using SqlCeConnection.


That's what he's using.


View PostThe Architect 2.0, on 13 August 2011 - 10:06 PM, said:

i'm calling a SQLCE database if that matters

Was This Post Helpful? 0
  • +
  • -

#6 The Architect 2.0  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 351
  • Joined: 22-May 08

Re: Using a Model class around a SQL Database

Posted 14 August 2011 - 11:53 PM

using the built-in SQLCE 3.5(?) 'local database' in VS 2010.

i used sqlmetal.exe to generate the appropriate .dbml files(and the other ones) for linq-to-sql

EDIT:

can someone point me to a good BROAD overview of databases and c#?

i keep hearing about ADO.NET, linq, entity framework, data contexts, dataviews, etc. and its all very confusing.

This post has been edited by The Architect 2.0: 14 August 2011 - 11:55 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1