sqlconnection

ADO.NET SqlData Client connections never go away

An asp.net application I am working on may have a couple hundred users trying to connect. We get an error that the maximum number of connections in the pool has been reached. I understand the concept of connection pools in ADO.NET although in testing I've found that a connection is left "sleeping" on the ms sql 2005 server days after the...

Why isn't SqlConnection disposed/closed?

Given the method: internal static DataSet SelectDataSet(String commandText, DataBaseEnum dataBase) { var dataset = new DataSet(); SqlConnection sqlc = dataBase == DataBaseEnum.ZipCodeDb ? new SqlConnection(ConfigurationManager.AppSettings["ZipcodeDB"]) : new SqlConnectio...

SqlConnection as a static singleton object

public class db { public static string connectionString = WebConfigurationManager.ConnectionStrings["connectString"].ConnectionString; public static SqlConnection OpenConnection() { SqlConnection connection = new SqlConnection(connectionString); connection.Open(); return connection; } }...

Is SqlCommand.Dispose() required if associated SqlConnection will be disposed?

I usually use code like this: using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString)) { var command = connection.CreateCommand(); command.CommandText = "..."; connection.Open(); command.ExecuteNonQuery(); } Will my command automatically disposed? Or not and I have to wr...

Is sqlconnection object closed and/or disposed on timeout?

If an sqlcommand is executed and times-out, is the respective sqlconnection closed and/or disposed? Thanks in advance! ...

TransactionScope question - how can I keep the DTC from getting involved in this?

(I know the circumstances surrounding the DTC and promoting a transaction can be a bit mysterious to those of us not in the know, but let me show you how my company is doing things, and if you can tell me why the DTC is getting involved, and if possible, what I can do to avoid it, I'd be grateful.) I have code running on an ASP.Net webs...

Impersonation: ASP.Net MVC Controller Action vs. Web Forms

Is there a difference with impersonation between an ASP.Net MVC controller actions vs. an ASP.Net Web Form? Using the exact same code within the same web project, I am able to successfully impersonate the Windows user when connecting to SQL Server from a Web Form but not from the Controller Action. Here is the code sample I am testing ...

java analog to C# SqlConnection and data access layer (my attempt)

I'm trying to work with java data access, so this with what I came up with: Tell me what do you think about this (It's a little bit like SqlConnection from C#) import java.sql.*; public class SqlConnection { Connection connection; public Connection GetConnection() {return connection;} public void Connect(String cs, Strin...

Login failed for user 'username'

I have a form that selects a bunch of rows from a table in my MSSQL server, now, this form is used to update data, which it does correctly, after I update the data using the form however, it redirects back to a page with a datagrid of all the rows in that table, and allows me to select another row to update, if I select the row I just up...

Is it important to Open a sql connection in the transactionscope.

I created a sqlconnection, CN1. Then this CN1 is opened. Later in the code there is a transactionscope. If I execute a sql command on this CN1 connection, is this within transaction? Code looks like this; SqlConnection cn1 = new SqlConnection(); cn1.Open(); //connection opened when there is no ambient transaction. ... using(Transactio...

SQL in web service best practices

I'm making a stateless web service which uses Microsoft SQL Server to read data (and only to read), without using transactions. What will be the best of the following: Starting SqlConnection at each call to the web service, or Storing SqlConnection in a static field. IMHO, the first approach will cost too much resources (if ten clien...

Overhead of creating new SqlConnection in c#

A while back I wrote an ORM layer for my .net app where all database rows are represented by a subclass of DatabaseRecord. There are a number of methods like Load(), Save() etc. In my initial implementation I created a connection to the DB in the constructor of DatabaseRecord e.g. connection = new SqlConnection( ConfigurationManager...

Creating an IDisposable class in c# which cleans up an SqlConnection when finished with

In an answer to a previous question somebody recommended: have the SqlConnection a member variable of your class, but make the class IDisposable and dispose of the SqlConnection when the class is disposed I have put together an implementation of this suggestion (below) but wanted to check that this implementation is correct (obviou...

How can I "detach" a SqlDataReader from its SqlConnection object?

I have a method ("GetDataReader," let's call it) that returns a SqlDataReader. It's inside a Singleton DataFactory class that maintains a persistent connection to the database. The problem with this is that after being returned, the DataReader is still "connected" to the Connection object in my DataFactory. So, I have to make sure the...

During Open(), SqlConnection.ServerVersion throws System.InvalidOperationException

When running a webservice, web page that knows how to respond. The service connects to a dbase. During the sqlconnection.open call, ASP .NET code throws the following exception: sqlConnection.ServerVersion' threw an exception of type 'System.InvalidOperationException' NOTE: I'm running this on my dev machine. When it ru...

SqlConnection.open() throws TransactionException 0xe0434f4d

Code works fine when connecting to a sql server 2005 dbase. but when connecting to a sql server 2008 dbase it fails. scenario: Webservice first connects to 2008 dbase fine. Then during a call in a COM+ object, the connect fails. Recently upgraded projects to use VS2008 and upgraded to Sql Server 2008. using (TransactionScope trans...

How to trace sql commands for a specific connection to db2?

I am in the process of setting up a central build server. The server is responsible to produce the official build artifacts that will be deployed to all environment. For one of the applications there is an build step that writes to a database. At deploy time we would need to run this build step to the appropriate environment. Since it is...

What disadvantages are there for leaving an SQL Connection open?

This seems to be a simple question, but I wonder the disadvantages of not calling the "close()" function. Thanks. ...

how many instances of SqlConnection should I use

Background: I have an application that I have nicely separated my interface logic from my middle tier logic which handles the queries to the database. I do a lot of custom sorting and narrowing so I'm not using many SqlDataSources and instead calling a lot of stored procedures with SqlCommands. I am using Forms Authentication to create...

When should I close the db connection?

Is it a must to close the connection in PHP script? ...