sqlconnection

Is SqlCommand.Dispose enough?

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...

Breakpoints in core .NET runtime?

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...

How can I tell how many SQL Connections I have open in a windows service?

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? ...

What is the proper way to ensure a SQL connection is closed when an exception is thrown?

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...

How to test SqlServer connection without opening a database

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...

Does .Net do clever connection management like PHP?

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...

Does .net SqlCommand.ExecuteReader close connection?

In this sentence: myCommand.ExecuteReader(CommandBehavior.CloseConnection) does it close connection in case of exception? ...

Why call SqlClient.SqlDataReader Close() method anyway?

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...

.net SqlConnection not being closed even when within a using { }

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 ...

How to find unclosed connection? Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

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...

Best way to handle sql-connections in webservice?

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...

How to use ADO.net Entity Framework with an existing SqlConnection?

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...

SQLConnection Pooling - Handling InvalidOperationExceptions

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...

Identifying underlying sql connection of SqlConnection object

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...

How to force SQLconnection to release a database???

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?? ...

Diagnosing SqlConnection leaks?

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? ...

How to get ASPNET to be recognized as a Trusted Connection by SQL Server 2005

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...

Windows Mobile - auto connect to Internet (GPRS) when opening SqlConnection (.NET)

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...

Not allowed to change the 'ConnectionString' property. The connection's current state is open.

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...

ExecuteReader requires an open and available Connection. The connection's current state is closed.

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...