Can I use this approach efficiently?
using(SqlCommand cmd = new SqlCommand("GetSomething", new SqlConnection(Config.ConnectionString))
{
cmd.Connection.Open();
// set up parameters and CommandType to StoredProcedure etc. etc.
cmd.ExecuteNonQuery();
}
My concern is : Will the Dispose method of the SqlCommand (which is calle...
I have a third party library that internally constructs and uses the SqlConnection class. I can inherit from the class, but it has a ton of overloads, and so far I have been unable to find the right one. What I'd like is to tack on a parameter to the connection string being used.
Is there a way for me to put a breakpoint in the .NET lib...
I'm seeing some errors that would indicate a "connection leak". That is, connections that were not closed properly and the pool is running out. So, how do I go about instrumenting this to see exactly how many are open at a given time?
...
I use a pattern that looks something like this often. I'm wondering if this is alright or if there is a best practice that I am not applying here.
Specifically I'm wondering; in the case that an exception is thrown is the code that I have in the finally block enough to ensure that the connection is closed appropriately?
public class S...
The title pretty much says it all. I want to create a SqlConnection and then check that connection without opening a database, cause at that point I don't know yet where will I connect to. Is it possible to do that?
The SqlConnection class has a 'Open' member which tries to open the database you'd set in the Database property, and if yo...
During an ASP.NET page load I'm opening and closing multiple System.Data.SqlClient.SqlConnections inside multiple controls contained in the page. I thought it would be a good idea instead to create a "pool" of connections and when opening a connection check to see if the connection string matches that of an open connection in the pool, a...
In this sentence:
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
does it close connection in case of exception?
...
Is the SqlClient.SqlDataReader a .NET managed object or not?
Why do we have to call the Close() method explicitly close an open connection?
Shouldn't running out of scope for such an object automatically close this?
Shouldn't garbage collector clean it up anyway?
Please help me understand what is the best practise here.
I have seen a r...
Please help!
Background info
I have a WPF application which accesses a SQL Server 2005 database. The database is running locally on the machine the application is running on.
Everywhere I use the Linq DataContext I use a using { } statement, and pass in a result of a function which returns a SqlConnection object which has been opened ...
I've had this problem before and found that basically I've got a connection that I'm not closing quickly enough (leaving connections open and waiting for garbage collection isn't really a best practice).
Now I'm getting it again but I can't seem to find where I'm leaving my connections open. By the time is see the error the database has...
I have a webservice that is called by up to 10 clients. The webservice is built up of 7 differnet asmx-pages and have about 100-200 functions in each page.
All those functions are working against a MSSQL2005 or MS SQL2000 database. Some periods of the day its heavy traffic from the clients and it seems like I run out of connections on t...
I have an existing asp.net website that uses an SqlConnection.
I have added the ADO.net Entity Framework.
I have successfully connected to the database and created the .edmx file.
I am able to connect through the Entity Framework with the connectionstring that is automatically generated.
I want to use the existing SqlConnection object...
I am designing a Highly Concurrent CCR Application in which it is imperative that I DO NOT Block or Send to sleep a Thread.
I am hitting SQLConnection Pool issues - Specifically getting InvalidOperationExceptions when trying to call SqlConnection.Open
I can potentially retry a hand full of times, but this isn't really solving the probl...
I can use GetHashCode() to identify an object but is there any way to identify the actual sql connection obtained by a SqlConnection object?
I'm (still) trying to debug a problem involving pooled connections and application roles and if I could reliably identify the underlying sql connection it could help a lot.
Here's some code that m...
I have written a small application, that can restore a database (C# and SQL2005), but after I have accessed the database, I can't drop it - it says that it is in use..
I guess it has to do with the SQLconnection-pooling, but can I force it to relase the database??
...
Hi all,
I'm running into an issue with a web application that is exhausting all available connections in the connection pool. I seem to recall some good tools used to diagnose all active connections, but am drawing a blank. What are some good options for diagnosing this issue?
...
Here's the situaiton. I'm working on developing a new website to access an old database. This is a DoD installation so there's lots of security around.
The current application is written in classic ASP, VBScript and some javascript. The new systems is ASP.NET.
Accessing the database in the old system meant hitting the server with yo...
Hello!
I've set up a GPRS connection on a mobile device running Windows Mobile 5.0. It connects on demand (e.g. when entering an URL in Internet Explorer).
However, connecting to a remote database (via SqlConnection) fails if the device isn't already connected, ie. it doesn't connect automatically. Is there a way to configure the devic...
Hello there!
First time user of stackoverflow, but I have followed its development over on Coding Horror.
I am having a massive headache with the above error. I have ELMAH installed and Google Analytics and as the site traffic has increased, so has the number of times I have seen this error.
I have done my best to follow the Microsof...
Ok, I asked about this very error earlier this week and had some very helpful answers and without doubt things have drastically improved since I started following the suggestions.
However, now I am using the 'correct', best practice method to access the database I still get this error on some functions and I cannot get it to disappear f...