Search Results

Search found 497 results on 20 pages for 'sqlconnection'.

Page 1/20 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Proper Usage of SqlConnection in .NET

    - by Jojo
    Hi guys, I just want an opinion on the proper usage or a proper design with regards to using SqlConnection object. Which of the 2 below is the best use: A data provider class whose methods (each of them) contain SqlConnection object (and disposed when done). Like: IList<Employee> GetAllEmployees() { using (SqlConnection connection = new SqlConnection(this.connectionString)) { // Code goes here... } } Employee GetEmployee(int id) { using (SqlConnection connection = new SqlConnection(this.connectionString)) { // Code goes here... } } or SqlConnection connection; // initialized in constructor IList<Employee> GetAllEmployees() { this.TryOpenConnection(); // tries to open member SqlConnection instance // Code goes here... this.CloseConnection(); // return } Employee GetEmployee(int id) { this.TryOpenConnection(); // tries to open member SqlConnection instance // Code goes here... this.CloseConnection(); // return } Or is there a better approach than this? I have a focused web crawler type of application and this application will crawl 50 or more websites simultaneously (multithreaded) with each website contained in a crawler object and each crawler object has an instance of a data provider class (above). Please advise. Thanks.

    Read the article

  • operator not defined for System.Data.SqlClient.SqlConnection and System.Data.SqlClient.SqlConnection

    - by Beta033
    i hope i'm just doing something wrong here. Ideally i'm trying to open the connection, open a transaction execute a ton of prebuilt sqlstatements (with parameters) against this connection then close the connection. ideally all in the same batch. It's easy enough to wrap this all in a for loop, however i'd like to use the forEach function of the list generic to set the connection as it'll probably be faster than my implementation of calling List.Item(i) in the loop but i get some strange errors. Dim sqlStatements As List(Of SqlCommand) = New List(Of SqlCommand) Dim conn As SqlClient.SqlConnection = New SqlConnection("...") sqlStatements.Item(0).Connection = conn 'Works sqlStatements.ForEach(Function(ByRef cmd As SqlCommand) cmd.Connection = conn) 'ERROR: Operator '=' is not defined for types 'System.Data.SqlClient.SqlConnection' 'and 'System.Data.SqlClient.SqlConnection What does this error really mean?

    Read the article

  • Under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope T

    - by Triynko
    What does it mean for an SqlConnection to be "enlisted" in a transaction? Does it simply mean that commands I execute on the connection will participate in the transaction? If so, under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope Transaction? See questions in code comments. My guess to each question's answer follows each question in parenthesis. Scenario 1: Opening connections INSIDE a transaction scope using (TransactionScope scope = new TransactionScope()) using (SqlConnection conn = ConnectToDB()) { // Q1: Is connection automatically enlisted in transaction? (Yes?) // // Q2: If I open (and run commands on) a second connection now, // with an identical connection string, // what, if any, is the relationship of this second connection to the first? // // Q3: Will this second connection's automatic enlistment // in the current transaction scope cause the transaction to be // escalated to a distributed transaction? (Yes?) } Scenario 2: Using connections INSIDE a transaction scope that were opened OUTSIDE of it //Assume no ambient transaction active now SqlConnection new_or_existing_connection = ConnectToDB(); //or passed in as method parameter using (TransactionScope scope = new TransactionScope()) { // Connection was opened before transaction scope was created // Q4: If I start executing commands on the connection now, // will it automatically become enlisted in the current transaction scope? (No?) // // Q5: If not enlisted, will commands I execute on the connection now // participate in the ambient transaction? (No?) // // Q6: If commands on this connection are // not participating in the current transaction, will they be committed // even if rollback the current transaction scope? (Yes?) // // If my thoughts are correct, all of the above is disturbing, // because it would look like I'm executing commands // in a transaction scope, when in fact I'm not at all, // until I do the following... // // Now enlisting existing connection in current transaction conn.EnlistTransaction( Transaction.Current ); // // Q7: Does the above method explicitly enlist the pre-existing connection // in the current ambient transaction, so that commands I // execute on the connection now participate in the // ambient transaction? (Yes?) // // Q8: If the existing connection was already enlisted in a transaction // when I called the above method, what would happen? Might an error be thrown? (Probably?) // // Q9: If the existing connection was already enlisted in a transaction // and I did NOT call the above method to enlist it, would any commands // I execute on it participate in it's existing transaction rather than // the current transaction scope. (Yes?) }

    Read the article

  • How can maintain a SqlConnection open always

    - by Salvador
    How can maintain a SqlConnection (or using another component) open (connected) always during the execution of my .Net app? I need this because my app needs to detect using this commnad exec sp_who2 how many instances of my app are connected to mydatabase, to restrict the access (license control). example A) my app executed from location1 check the number of my apps connected to the sql server using exec sp_who2 if the number of my applications < MaxLicencesConnected then start my app and open a sqlconnection B) my app executed from location2 check the number of my apps connected to the sql server using exec sp_who2 if the number of my applications = MaxLicencesConnected then close my application sorry for my english. thanks in advance.

    Read the article

  • Passing around a SqlConnection

    - by Chris
    I have created a TransactionScope and within the scope various items are created and updated in the database. During this process I make a lot of calls to the database. Originally I opened a SqlConnection in the beginning of the TransactionScope and passed it around to any function that made a DB call then I closed the connection after all the calls are made and before the transaction commits. Is it better to do this or to open and close a connection for each call?

    Read the article

  • how to close a sqlconnection in asp.net

    - by stighy
    Hi guys, i would like to know if there's something wrong in this asp.net code: mydatareader = mycmd.executeReader() if myDataReader.HasRow then // Do something end if myConnection.Close() If i avoid to call a "MyDataReader.Close()" does the connection close anyway ? I ask this because i'm assuming that if call a "MyConn.Close" it automatically close the associated datareader... or am i wrong ? Thanks

    Read the article

  • Is closing/disposing an SqlDataReader needed if you are already closing the sqlconnection?

    - by Brian
    I noticed This question, but my question is a bit more specific. Is there any advantage to using using (SqlConnection conn = new SqlConnection(conStr)) { using (SqlCommand command = new SqlCommand()) { // dostuff } } instead of using (SqlConnection conn = new SqlConnection(conStr)) { SqlCommand command = new SqlCommand(); // dostuff } Obviously it does matter run more than one command with the same connection, since closing an SqlDataReader is more efficient than closing and reopening a connection (calling conn.Close();conn.Open(); will also free up the connection). I see many people insist that failure to close the DataReader means leaving open connection resources around, but doesn't that only apply if you don't close the connection?

    Read the article

  • SQLConnection.Open(); throwing exception

    - by flavour404
    Hi, Updating an old piece of software but in order to maintain backward compatibility I need to connect to a .mdb (access) database. I am using the following connection but keep getting an exception, why? I have validated the path, database existence etc. and that is all correct. string Server = "localhost"; string Database = drive + "\\btc2\\state\\states.mdb"; string Username = ""; string Password = "Lhotse"; string ConnectionString = "Data Source = " + Server + ";" + "Initial Catalog = " + Database + ";" + "User Id = '';" + "Password = " + Password + ";"; SqlConnection SQLConnection = new SqlConnection(); try { SQLConnection.ConnectionString = ConnectionString; SQLConnection.Open(); } catch (Exception Ex) { // Try to close the connection if (SQLConnection != null) SQLConnection.Dispose(); // //can't connect // // Stop here return false; }

    Read the article

  • System.Data.Sqlconnection

    - by Surya sasidhar
    hi, in my application when i type sqlconnection it is not showing any intellisence, i added the namespace System.Data.Sqlclient not only sqlconnection even i am not getting Page calss can u help me. actually i am sharing this application from my company server.

    Read the article

  • When should I open and close a connection to SQL Server

    - by Martin
    I have a simple static class with a few methods in it. Each of those methods open a SqlConnection, query the database and close the connection. This way, I am sure that I always close the connection to the database, but on the other hand, I don't like to always open and close connection. Below is an example of what my methods look like. public static void AddSomething(string something) { using (SqlConnection connection = new SqlConnection("...")) { connection.Open(); // ... connection.Close(); } } Considering that the methods are inside a static class, should I have a static member containing a single SqlConnection? How and when should I drop it? What are the best practices?

    Read the article

  • Remote connection to SQL Server Express fails

    - by worlds-apart89
    I have two computers that share the same Internet IP address. Using one of the computers, I can remotely connect to a SQL Server database on the other. Here is my connection string: SqlConnection connection = new SqlConnection(@"Data Source=192.168.1.101\SQLEXPRESSNI,1433;Network Library=DBMSSOCN;Initial Catalog=FirstDB;Persist Security Info=True;User ID=username;Password=password;"); 192.168.1.101 is the server, SQLEXPRESSNI is the SQL Server instance name, and FirstDB is the name of the database. Now, I have another computer with a different Internet IP address. I want to connect to the server above using the third computer that does not belong to my local area network. I dont have access to that third computer at the moment, so I want to use (if possible) the client computer in LAN again. SqlConnection connection = new SqlConnection(@"Data Source=SharedInternetIP\SQLEXPRESSNI,1433;Network Library=DBMSSOCN;Initial Catalog=FirstDB;Persist Security Info=True;User ID=username;Password=password;"); Does not work Note that I am a beginner, so I am not quite sure what I am doing even though I know what I want to do. By passing the Internet IP to the SqlConnection object rather than the local IP address, how can I successfully connect to the server computer, using the client computer in the same network? Also note that my ultimate goal is to connect to the server with an external client, but I don't have access to that computer right now. I'd appreciate any help.

    Read the article

  • ASP .NET 2.0 cannot open SQLConnection

    - by user162117
    Using: IIS 6; Anonymous Authentication (with a user that belongs to the administrators group); SQL Server 2005; .NET 2.0 Web.config: <system.web> <securityPolicy> <trustLevel name="Full" policyFile="internal" /> </securityPolicy> </system.web> <identity impersonate="true"/> I have this exception when I try to Open a SQLConnection: Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. What could it be?

    Read the article

  • how to get the sql connection

    - by sweetsecret
    FS_Setting is a VB class which has all the details of the connections ie: Public Class FS_Setting Public Function Get_RS_Connection() As SqlConnection Try Get_RS_Connection = New SqlConnection("Data Source=***********;User ID=sa;Password=*****;database=*********") Catch ex As System.Exception Throw New System.Exception("Get_RS_Connection Error:" + ex.Message) End Try End Function I need to call the function Get_RS_Connection() in a different class instead of getting the connection all the way again and hard coding.... I want to call the above class where the SQL connection is declared Namespace FS_Library Public Class FS_Errorlog Inherits FS_BaseClass Try **cn = New SqlConnection("Data Source=***********;UserID=sa;Password=*****;database=*********")** cmd = New SqlCommand("dbo.FS_ErrorLog_ADD", cn) cmd.CommandType = CommandType.StoredProcedure cmd.CommandTimeout = Convert.ToInt32(ConfigurationSettings.AppSettings("Command_Timeout")) Me.AddParameter(cmd, "@p_tableKey", SqlDbType.Int, tableKey) Me.AddParameter(cmd, "@p_FunctionCode", SqlDbType.Int, FunctionCode) Me.AddParameter(cmd, "@p_TableAlias", SqlDbType.VarChar, TableAlias) Me.AddParameter(cmd, "@p_ValidationCode", SqlDbType.Int, ValidationCode) If Filename = "" Then Filename = "N/A" End If Me.AddParameter(cmd, "@p_FileName", SqlDbType.VarChar, Filename) Me.AddParameter(cmd, "@p_Message", SqlDbType.VarChar, Message) Me.AddParameter(cmd, "@p_CreateUser", SqlDbType.VarChar, userID) Me.AddParameter(cmd, "@p_UserActionID", SqlDbType.UniqueIdentifier, UserActionID) cn.Open()

    Read the article

  • Test sql connection without throwing exception

    - by Alexandre Pepin
    To test if i can connect to my database, I execute the following code : using (SqlConnection connection = new SqlConnection(myConnectionString)) { try { connection.Open(); canConnect = true; } catch (SqlException) { } } This works except it throws an exception if the connection failed. Is there any other way to test a Sql connection that doesn't throw an exception ? Edit : To add precision, i'm asking if there is a simple method that does that without having to open the connection and catch exceptions that can occur

    Read the article

  • Using one sqlconnection/sqlcommand through 2 DB-bound methods

    - by dotnetdev
    I have a class with a method which gets data from a database through a SELECT stored proc. This method uses a SqlDbReader by returning ExecuteReader() on a SqlCommand. The connection and everything is made in this method, with fields (such as connection string) set as class level fields. I now need to populate an array based on the results of this query (so the columns of each row will go into the array with its own index). However, this query will not select all of the data from one table which is involved. I can write the queries to get what I need, but how can I use one connection throughout the class? If I instantiate the connection object and call Open() in the constructor, I get an exception @ runtime. I'm hoping for something like this: // At class level: sqlconn.Open(); // sqlcommand set up Method() { // Fire stored proc // Insert results in a collection } Method2() { // Pass same collection in (use same one), // Add new row columns into same collection } How can I do this with strict performance in mind? Thanks

    Read the article

  • SQL Server Connection Timeout C#

    - by Termin8tor
    First off I'd like to let everyone know I have searched my particular problem and can't seem to find what's causing my problem. I have an SQL Server 2008 instance running on a network machine and a client I have written connecting to it. To connect I have a small segment of code that establishes a connection to an sql server 2008 instance and returns a DataTable populated with the results of whatever query I run against the server, all pretty standard stuff really. Anyway the issue is, whenever I open my program and call this method, upon the first call to my method, regardless as to what I've set my Connection Timeout value as in the connection string, it takes about 15 seconds and then times out. Bizarrely though the second or third call I make to the method will work without a problem. I have opened up the ports for SQL Server on the server machine as outlined in this article: How to Open firewall ports for SQL Server and verified that it is correctly configured. Can anyone see a particular problem in my code? string _connectionString = "Server=" + @Properties.Settings.Default.sqlServer + "; Initial Catalog=" + @Properties.Settings.Default.sqlInitialCatalog + ";User Id=" + @Properties.Settings.Default.sqlUsername + ";Password=" + @Properties.Settings.Default.sqlPassword + "; Connection Timeout=1"; private DataTable ExecuteSqlStatement(string command) { using (SqlConnection conn = new SqlConnection(_connectionString)) { try { conn.Open(); using (SqlDataAdapter adaptor = new SqlDataAdapter(command, conn)) { DataTable table = new DataTable(); adaptor.Fill(table); return table; } } catch (SqlException e) { throw e; } } } The SqlException that is caught at my catch is : "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." This occurs at the conn.Open(); line in the code snippet I have included. If anyone has any ideas that'd be great!

    Read the article

  • Does DataAdapter.Fill() close its connection when an Exception is thrown?

    - by motto
    Hi, I am using ADO.NET (.NET 1.1) in a legacy app. I know that DataAdapter.Fill() opens and closes connections if the connection hasn't been opened manually before it's given to the DataAdapter. My question: Does it also close the connection if the .Fill() causes an Exception? (due to SQL Server cannot be reached, or whatever). Does it leak a connection or does it have a built-in Finally-clause to make sure the connection is being closed. Code Example: Dim cmd As New SqlCommand Dim da As New SqlDataAdapter Dim ds As New DataSet cmd.Connection = New SqlConnection(strConnection) cmd.CommandText = strSQL da.SelectCommand = cmd da.Fill(ds)

    Read the article

  • How bad is opening and closing a SQL connection for several times? What is the exact effect?

    - by Eren
    For example, I need to fill lots of DataTables with SQLDataAdapter's Fill() method: DataAdapter1.Fill(DataTable1); DataAdapter2.Fill(DataTable2); DataAdapter3.Fill(DataTable3); DataAdapter4.Fill(DataTable4); DataAdapter5.Fill(DataTable5); .... .... Even all the dataadapter objects use the same SQLConnection, each Fill method will open and close the connection unless the connection state is already open before the method call. What I want to know is how does unnecessarily opening and closing SQLConnections affect the performance of the application. How much does it need to scale to see the bad effects of this problem (100,000s of concurrent users?). In a mid-size website (daily 50000 users) does it worth bothering and searching for all the Fill() calls, keeping them together in the code and opening the connection before any Fill() call and closing afterwards?

    Read the article

  • CommandBuilder and SqlTransaction to insert/update a row

    - by Jesse
    I can get this to work, but I feel as though I'm not doing it properly. The first time this runs, it works as intended, and a new row is inserted where "thisField" contains "doesntExist" However, if I run it a subsequent time, I get a run-time error that I can't insert a duplicate key as it violate the primary key "thisField". static void Main(string[] args) { using(var sqlConn = new SqlConnection(connString) ) { sqlConn.Open(); var dt = new DataTable(); var sqlda = new SqlDataAdapter("SELECT * FROM table WHERE thisField ='doesntExist'", sqlConn); sqlda.Fill(dt); DataRow dr = dt.NewRow(); dr["thisField"] = "doesntExist"; //Primary key dt.Rows.Add(dr); //dt.AcceptChanges(); //I thought this may fix the problem. It didn't. var sqlTrans = sqlConn.BeginTransaction(); try { sqlda.SelectCommand = new SqlCommand("SELECT * FROM table WITH (HOLDLOCK, ROWLOCK) WHERE thisField = 'doesntExist'", sqlConn, sqlTrans); SqlCommandBuilder sqlCb = new SqlCommandBuilder(sqlda); sqlda.InsertCommand = sqlCb.GetInsertCommand(); sqlda.InsertCommand.Transaction = sqlTrans; sqlda.DeleteCommand = sqlCb.GetDeleteCommand(); sqlda.DeleteCommand.Transaction = sqlTrans; sqlda.UpdateCommand = sqlCb.GetUpdateCommand(); sqlda.UpdateCommand.Transaction = sqlTrans; sqlda.Update(dt); sqlTrans.Commit(); } catch (Exception) { //... } } } Even when I can get that working through trial and error of moving AcceptChanges around, or encapsulating changes within Begin/EndEdit, then I begin to experience a "Concurrency violation" in which it won't update the changes, but rather tell me it failed to update 0 of 1 affected rows. Is there something crazy obvious I'm missing?

    Read the article

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

    - by larryq
    (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 webserver. We have one database, SQL 2008. Our data access code looks something like this-- We have a data access layer that uses a wrapper object for SQLConnections and SQLCommands. Typical use looks like this: void method1() { objDataObject = new DataAccessLayer(); objDataObject.Connection = SomeConnectionMethod(); SqlCommand objCommand = DataAccessUtils.CreateCommand(SomeStoredProc); //create some SqlParameters, add them to the objCommand, etc.... objDataObject.BeginTransaction(IsolationLevel.ReadCommitted); objDataObject.ExecuteNonQuery(objCommand); objDataObject.CommitTransaction(); objDataObject.CloseConnection(); } So indeed, a very thin wrapper around SqlClient, SqlConnection etc. I want to run several stored procs in a transaction, and the wrapper class doesn't allow me access to the SqlTransaction so I can't pass it from one component to the next. This led me to use a TransactionScope: using (TransactionScope tx1 = new TransactionScope(TransactionScope.RequiresNew)) { method1(); method2(); method3(); tx1.Complete(); } When I do this, the DTC gets involved, and unfortunately our webservers don't have "allow remote clients" enabled in the MSDTC settings-- getting IT to allow that will be a fight. I'd love to avoid DTC becoming involved but can I do it? Can I leave out the transactional calls in methods1-3() and just let the TransactionScope figure it all out?

    Read the article

  • Does EF 4 Code First's ContextBuilder Dispose its SqlConnection?

    - by Eric J.
    Looking at Code First in ADO.Net EF 4 CTP 3 and wondered how the SqlConnection in their walkthrough is disposed. Is that the responsibility of ContextBuilder? Is it missing from the example? var connection = new SqlConnection(DB_CONN); var builder = new ContextBuilder<BloggingModel>(); var connection = new SqlConnection(DB_CONN); using (var ctx = builder.Create(connection)) { //... }

    Read the article

  • DAL Exception handling in a MVP application

    - by Chathuranga
    In a MVP win forms application I'm handling exceptions as follows in DAL. Since the user messaging is not a responsibility of DAL, I want to move it in to my Presentation class. Could you show me a standard way to do that? public bool InsertAccount(IBankAccount ba) { string selectStatement = @"IF NOT EXISTS (SELECT ac_no FROM BankAccount WHERE ac_no=@ac_no) BEGIN INSERT INTO BankAccount ..."; using (SqlConnection sqlConnection = new SqlConnection(db.ConnectionString)) { using (SqlCommand sqlCommand = new SqlCommand(selectStatement, sqlConnection)) { try { sqlConnection.Open(); sqlCommand.Parameters.Add("@ac_no", SqlDbType.Char).Value = ba.AccountNumber; // // sqlCommand.ExecuteNonQuery(); return true; } catch (Exception e) { MessageBox.Show(("Error: " + e.Message)); } if (sqlConnection.State == System.Data.ConnectionState.Open) sqlConnection.Close(); return false; } } }

    Read the article

  • Why is my mssql query failing?

    - by Eric Reynolds
    connect(); $arr = mssql_fetch_assoc(mssql_query("SELECT Applications.ProductName, Applications.ProductVersion, Applications.ProductSize, Applications.Description, Applications.ProductKey, Applications.ProductKeyID, Applications.AutomatedInstaller, Applications.AutomatedInstallerName, Applications.ISO, Applications.ISOName, Applications.Internet, Applications.InternetURL, Applications.DatePublished, Applications.LicenseID, Applications.InstallationGuide, Vendors.VendorName FROM Applications INNER JOIN Vendors ON Applications.VendorID = Vendors.VendorID WHERE ApplicationID = ".$ApplicationID)); $query1 = mssql_query("SELECT Issues.AppID, Issues.KnownIssues FROM Issues WHERE Issues.AppID=".$ApplicationID); $issues = mssql_fetch_assoc($query1); $query2 = mssql_query("SELECT ApplicationInfo.AppID, ApplicationInfo.Support_Status, ApplicationInfo.UD_Training, ApplicationInfo.AtomicTraining, ApplicationInfo.VendorURL FROM software.software_dbo.ApplicationInfo WHERE ApplicationInfo.AppID = ".$ApplicationID); $row = mssql_fetch_assoc($query2); function connect(){ $connect = mssql_connect(DBSERVER, DBO, DBPW) or die("Unable to connect to server"); $selected = mssql_select_db(DBNAME, $connect) or die("Unable to connect to database"); return $connect; } Above is the code. The first query/fetch_assoc works perfectly fine, however the next 2 queries fail and I cannot figure out why. Here is the error statement that shows up from php: Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'Issues'. (severity 16) in /srv/www/htdocs/agreement.php on line 47 Warning: mssql_query() [function.mssql-query]: General SQL Server error: Check messages from the SQL Server (severity 16) in /srv/www/htdocs/agreement.php on line 47 Warning: mssql_query() [function.mssql-query]: Query failed in /srv/www/htdocs/agreement.php on line 47 Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in /srv/www/htdocs/agreement.php on line 48 Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'software.software_dbo.ApplicationInfo'. (severity 16) in /srv/www/htdocs/agreement.php on line 51 Warning: mssql_query() [function.mssql-query]: General SQL Server error: Check messages from the SQL Server (severity 16) in /srv/www/htdocs/agreement.php on line 51 Warning: mssql_query() [function.mssql-query]: Query failed in /srv/www/htdocs/agreement.php on line 51 Warning: mssql_fetch_assoc(): supplied argument is not a valid MS SQL-result resource in /srv/www/htdocs/agreement.php on line 52 The error clearly centers around the fact that the query is not executing. In my database I have a table called Issues and a table called ApplicationInfo so I am unsure why it is telling me that they are invalid objects. Any help would be appreciated. Thanks, Eric R.

    Read the article

  • How to tell if a datareader is open on a connection and close it

    - by Earlz
    Hi, I'm setting up a little thing for connection pooling and on of the more common bugs that we have occur(its always an easy fix, but we just can't remember reader.Close()!) it is when we have a connection that is used by a lot of classes/methods and one method opens a data reader and forgets to close it. This isn't really bad cause a lot of times all you have to do is go into the debugger and go up one level and see the function before it was and check if it had an unclosed data reader. Now, here is the bigger problem. In this connection pool, if a datareader is open, then it's not known until a thread gets a connection and tries to use it and the thing that originally opened the data reader may no longer even be alive. So quite simply, how can you detect if a data reader is open on a connection and is there a way to close the reader without closing the connection?

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >