Am I doing something in terms of joining compounds?

I have a class that uses both ADO.NET and LINQ to access a pair of databases on a single server. The tables in the database are not extensive, so the objects of the object are quite light. I wrote the code as well as I did, using experience and clean articles, of course. For instance...

http://dotnetperls.com/sqldataadapter http://www.velocityreviews.com/forums/t71781-set-maximum-pool-size-in-web-config.html http://msdn.microsoft.com/en- us / library / ms971481 # adonetbest_topic5

The server that my code runs on only works with my code and is not the same server as the db host. From a look at the connections going to the database server from my .NET application server (this is a Windows service, but I do not want to dwell on this, since it seems inconsequential now), the number of connections is about 200, but it will certainly be less than that; It should be around 10 since I set Max Pool Size to 10 in appSettings.config.

Can someone take a look at my connection code and tell me that I am doing something that will make the connections shoot, please?

Here is my LINQ DB context creation:

private const string ConnectionKey = "SQL2";
protected static string ConnectionString
{
    get
    {
        return _connectionString = (_connectionString == null) ? ConfigurationManager.ConnectionStrings[ConnectionKey].ConnectionString : _connectionString;
    }
}
private static string _connectionString = null;

protected static PricingDBDataContext ContextDB
{
    get
    {
        if (_context == null)
        {
            _context = new PricingDBDataContext(ConnectionString);
        }

        return _context;
    }
}
private static PricingDBDataContext _context = null;

Here is part of ADO.NET:

protected DataSet GetDataSet(bool isSproc, string cmdStr, params object[] args)
{
    using (SqlConnection conn = new SqlConnection(ConnectionString))
    {
        using (SqlCommand cmd = new SqlCommand(cmdStr, conn))
        {
            cmd.CommandType = isSproc ? CommandType.StoredProcedure : CommandType.Text;
            for (int index = 0; index < args.Length; index += 2)
                cmd.Parameters.AddWithValue(args[index].ToString(), args[index + 1]);
            conn.Open();
            DataSet set = FillSet(cmd);
            conn.Close();
            return set;
        }
    }
}

private DataSet FillSet(SqlCommand cmd)
{
    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
    DataSet set = new DataSet();
    adapter.Fill(set);
    return set;
}

Thank,

Mt.

+3
source share
1 answer

, - , , , . .Net

, :

  • ADO , ​​
  • ado.net IDisposable , using. , , .
  • Linq 2 SQL EF IDisposable
+2

Source: https://habr.com/ru/post/1789516/


All Articles