On Aug 20, 2012, at 3:28 PM, Philippe Grohrock philippe.grohr...@gmail.com
wrote:
Thanks for the reply already and I'm sorry, I should've added the lines of
code.
static class GlobalVariables
{
public static MySqlConnection connection = new connection();
}
To add to what Jonathan said, trying to reuse the same connection for
everything can also lead to concurrent access issues, if more than one
thread accesses the connection at a given time. I've seen such issues when
using Entity Framework. Besides, creating a new connection is really cheap.
On Aug 17, 2012, at 5:49 PM, Philippe Grohrock philippe.grohr...@gmail.com
wrote:
1. Is it bad/good style to have a public class that implements global
variables?
How do you define global variable? :-)
`public static` fields are Very Badâ„¢, unless they're `readonly`. This is
because there's
Thanks for the reply already and I'm sorry, I should've added the lines of
code.
This way the whole program has access to it and can modify/query the DB when
needed (this is what I meant with global). At the moment I have 2 of my
windows using that connection, but there might be more in the
I'd create ConnectionFactory class, although feel free to ignore me,
just thinking off the top of my head! :-)
public class ConnectionFactory
{
private static MySqlConnection _connection;
public MySqlConnection GetConnection()
{
if (_connection == null)
{
Just in case no-one else spots it, you'll need a static keyword on
that GetConnection() declaration, otherwise you have to create an
instance to get a reference to the private static variable, which is
just odd :)
On 20/08/12 20:45, James Wright wrote:
I'd create ConnectionFactory
-
From: Philippe Grohrock philippe.grohr...@gmail.com
Date: Mon, 20 Aug 2012 19:28:07
To: mono-list@lists.ximian.com
Subject: Re: [Mono-list] Questions about coding style
Thanks for the reply already and I'm sorry, I should've added the lines of
code.static class GlobalVariables
Be carefull about this way of working with DB. You must free the
connections as fast as you can and I'm not sure you can do like this way.
Basically the connection gets initialised when the application starts and
every time I need a query, the connection gets opened, queried, closed, but
not
Unless I'm mistaken .NET connections are pooled for you, so I don't
think you'll be gaining much from keeping one instance of the connection
always open as the framework is already doing just that. My advice is
don't worry about it until you have to... chances are it won't be a
problem in
Unless I'm mistaken .NET connections are pooled for you, so I don't think
you'll be gaining much from keeping one instance of the connection always
open as the framework is already doing just that. My advice is don't worry
about it until you have to... chances are it won't be a problem in
Yes I am currently working alone, but I still think that learning about some
coding style isn't too bad after all, so I have two questions and I thought
I'd ask them both in the general section.
1. Is it bad/good style to have a public class that implements global
variables? My program readys a
11 matches
Mail list logo