static data access

Discussion in 'ASP .Net Datagrid Control' started by Nomadass, Apr 6, 2005.

  1. Nomadass

    Nomadass Guest

    hi,
    I have a static class for data access. what if i
    declare some private attribute like this.
    private static constr =
    ConfigurationSettings.ConnectionStrings["mydata"].ConnectionString;

    private sqlconnection con = new sqlconnection(constr);

    Does these two statements mean that the connection is always open?

    thanks in advance.
    Nomadass, Apr 6, 2005
    #1
    1. Advertising

  2. Never use the static connection.

    You should use just static property that returns connction string.

    public class test
    {
    public static string ConnectionString
    {
    get
    {
    return ConfigurationSettings.AppSettings["your key"];
    }
    }
    }

    public class con
    {

    public void aaa()
    {
    SqlConnection con = new SqlConnection(test.ConnectionString)

    ....
    con.Open();
    ...
    con.Close();
    }
    }

    "Nomadass" <> wrote in message
    news:...
    > hi,
    > I have a static class for data access. what if i
    > declare some private attribute like this.
    > private static constr =
    > ConfigurationSettings.ConnectionStrings["mydata"].ConnectionString;
    >
    > private sqlconnection con = new sqlconnection(constr);
    >
    > Does these two statements mean that the connection is always open?
    >
    > thanks in advance.
    Michael Tkachev, Apr 8, 2005
    #2
    1. Advertising

  3. Nomadass

    Nomada ss Guest

    thank you very much for your reply.

    now I have another problem about design.

    I follow the three tiers desgin. presentation tier.
    business tier. and data tier.

    As I am develop using C#, ASP.net. sqlServer 2005.
    In the data tier i have three layers.
    at the buttom is the data store. right above it is
    procedures. as it provides an hidden of queries changes
    from the layer above. the data access layer which is written in C# to
    access
    data.

    My problem is in the design of this data access layer.
    since all my connection to sqlserver. so the connection
    are all the same. and command are all stored procedure type.
    which means there should be a shared property in this layer.
    that is why I have a static connection which can be used by
    every connection to database. in such case. i need to serialize the
    connection open() method. which is not making
    use of the sqlserver can have sever connection opens at the same time.
    sqlsever action does not really open a new connection for every query.
    if the connection string are the same. so at the user side we may open
    more connections then the sqlserver. this is also a kind of waste. in
    another words.
    we open many connections at the user side, but the sqlserver side only
    have several connecitons to map this.

    to solver this problem. I propose a design that, at coding side. client
    of sqlserver, I construct two arrays or queues.
    on is for storing the connection are being used, another for the
    conneciton currently free. if a new connection is needed, I check the
    free queue first to see whether any idle connectin there, if it is, use
    it, otherwise, declare a new one, enqueue to the busy queue. is this
    method worthy or sounds reasonable? or i am just try to structure
    something useless

    I know this description is rather vagour, if you do get it.
    please give me suggestion.

    *** Sent via Developersdex http://www.developersdex.com ***
    Nomada ss, Apr 11, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus Dehmann
    Replies:
    5
    Views:
    2,666
    red floyd
    Jul 1, 2004
  2. Robin
    Replies:
    0
    Views:
    401
    Robin
    Jun 6, 2007
  3. Neviton
    Replies:
    9
    Views:
    435
    Alf P. Steinbach
    Sep 17, 2007
  4. dolphin
    Replies:
    3
    Views:
    1,319
    Pete Becker
    Dec 5, 2007
  5. Savvoulidis Iordanis

    XML data access or DB data access ?

    Savvoulidis Iordanis, Jan 7, 2009, in forum: ASP .Net
    Replies:
    2
    Views:
    396
    Savvoulidis Iordanis
    Jan 7, 2009
Loading...

Share This Page