.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

how to close underlying DbConnection without using "Using" statement

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :ASP.Net

Here's my  code,  I am using "Data Access Application Block"  in ObjectDataSource's class file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

namespace cHospital
    public class Hospital
        private Database _db = EnterpriseLibraryContainer.Current.GetInstance<Database>("Conn");
        public SqlDataReader sDR;

        public SqlDataReader GetHospitals()

            RefCountingDataReader dr = (RefCountingDataReader)_db.ExecuteReader("GetHospitals");
            return (SqlDataReader)dr.InnerReader;

in my code, I didnt dispose the dataReader.  will it mess up my connection management ?  I want to make sure that DbConnection is properly closed.

I found this from "hands on lab".
"You are not doing any connection management here, but it is very important to Dispose the data reader returned. This is accomplished by the using statement in the code above. When the data reader is disposed, the underlying DbConnection is also closed."

please let me know if what I did is ok, i

View Complete Post

More Related Resource Links

way of calling "javascript function of parent window from child window."

The article way of calling "javascript function of parent window from child window." was added by raja.s on Sunday, June 06, 2010.

Hi,Here i am going to explain how to call the javascript function of a parent window from the child window(pop-Up).Some may know before reading this post.Parent Java Script Function:script language="Javascript" type="text/javascript">

Regular Expression to match "="(45167)" and retrieve only the code inside parentheses



Need a Regular Expression to match "=&quot;(45167)" and retrieve only the code inside  parentheses say 45167

thanks in advance

replace "


when i look into my list and recieve the field data.

i recieve "30&quot;"

the output must be 30".

i'm dooing the following, but my result is 30\".

String modifyWord = SPEncode.HtmlEncode(proditem["code number"].ToString());
String productCodeNumber = modifyWord.Replace("&quot;", "\"");

what im i dooing wrong?


Activation error occured while trying to get instance of type Database, key "DBName"


Im using Enterprise library 5.0
I have a scenario, where I have to access two different databases in my application.

Basically this application is a webservice,delployed on my local for testing purpose.
I'm trying to access this web method from diffent windows application, default connection works fine but the other database throw's exception.

Problem is only my defaultDatabase is works fine, if I change defaultDatabase="MYCON1" with "MYCON2" it works fine, if I try to access the other database which is not default, throws exception.

<dataConfiguration defaultDatabase="MYCON1" />
<add name="MYCON1" connectionString="Data Source=server1;Initial Catalog=dbName1;User Id=Username1;Password=password1;"

" />
<add name="MYCON2" connectionString="Data Source=Server2;Initial Catalog=dbName2;User Id=Username2;Password=password2;"
providerName="System.Data.SqlClient" />

Database myDB=EnterpriseLibraryContainer.Current.GetInstance<Database>(); --> works fine for the default database (MYCON1)

Database myDB=EnterpriseLibraryContainer.Current.GetInstance<Database>("MYCON2"); --> Error message, see below

Activation e

Help me error "An operations error occurred" !



 I am trying write function to check User in Active Directory 

This my code :

            DirectoryEntry de = new DirectoryEntry("LDAP://myDomain");
            DirectorySearcher deSearch = new DirectorySearcher();
            deSearch.SearchRoot = de;

            deSearch.Filter = "(&(objectClass=user)(sAMAccountName=" + userName + "))";
            deSearch.SearchScope = SearchScope.Subtree;
            SearchResult results = deSearch.FindOne(); //-->Error here

            if (results != null)
                return true;

            return false;
        catch (Exception ex)
            throw new Exception(ex.Message);
When I run on Localhost (with IP : it very well, but I get other PC (in the same domain with IP : connect to PC (

PRB - ASP.NET "White Screen of Nothing" "Internet Explorer cannot display the webpage


PRB - ASP.NET "White Screen of Nothing" "Internet Explorer cannot display the webpage"

Please help,

We have a ASP.NET website that some times gets pages to lock up, with no content, all white screen, that eventually time out in IE to return an IE error page title "Internet Explorer cannot display the webpage". Note the spelling. We refer to this as the "White Screen of Nothing". 

Logs from IIS, show no errors (no 400+ status codes), and in fact, show the page that IE goes into the "White Screen of Nothing" for, as status code 200 in the IIS logs. Also, internal server-side ASP.NET tracing, show all code running as expected.

Trying to reproduce this error is difficult. It does not occur consistently. At best, if we open pages, close them, and repeat this as fast as we can, it will eventually happen on attempt to open a page and/or the refesh of a frame. It is not always the same page twice.

Some pages use AJAX controls. Most use GridViews. A few use Responce.Redirect. Nothing consistant.

Searches for causes of the "White Screen of Nothing" or the "Internet Explorer cannot display the webpage" are all over the place, and do not seem to be related.

We have managed to trap one instance of the "White Screen of Nothing" while in a Visual Studio 2008 debug session, where a weird, unknown thread was locked with the call

implement functionality like "word art"?



I want to know is it possible to open word art option by clicking on button ?

and if so how can i do this ?and after that i also want to convert that into image.

please help me.ITS VERY URGENT.

Any help will be appreciated.

Thank You.

Passing Linq Statement between master and content page


I usually work with windows forms, and am just starting to work with ASP.Net, so appologies if this is a dumb question!

I have a master page which has a search button on it. The results of this are built up using a Linq statement and if there are any results, I want to display the results in a contents page.

On the masterpage, I have the following code:

Private _res

    Public Overridable ReadOnly Property SearchRes()
            Return _res
        End Get
    End Property

 Private Sub DoSearch()
   'some code to get a linq result

    If res.Any Then
            _res = res
            Server.Transfer("SearchResults.aspx", True)
            'no results
            LabelNoRes.Visible = True
        End If
 End Sub

On the SearchResults.aspx page I have this code.

Dim m As pxSite = CType(Page.Master, MasterPage)
        If m.SearchRes IsNot Nothing Then
            Label1.Text = "Results found = " & m.SearchRes.Count
        End If

m.searchRes is always nothing. 

What am I doing wrong here?


WebDev.WebServer.exe has encounted a problem and needs to close when trying to view page in browser


Hi, whenever I load an aspx page in vwde2008, I get the message in the subject of this post.  After I click Ok on that, I get a dialog box, Unable to Connect to the ASP.Net development center.  What can I do to troubleshoot?

I am using Windows XP SP3, vwde2008 with SP1, on a HP desktop.  Also using Office 2003 if that is relevant at all.

Thanks, Justin

ReportViewer :: Failed to enable constraints. But my statement is valid!!

  • A
  • n error has occurred during report processing.
      • Exception has been thrown by the target of an invocation.
        • Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

    Why do I keep getting this error, even when not using any data on the report. When I run the query in SQL server I get a resultset. However when I try to render the report I get this error.


    Whats wrong with this statement


    Im trying to updated some old ASP pages with some new .net pages and cant seem to get this update statement to work. I need to update the current ASP code below and then once thats working im going to use that same statement in a procedure for all our new .Net pages..

    So can anyone see what im doing wrong by inserting the 2nd column to the update statement?

    strSqual = "update tas set date_completed='" & TransDate & ", trans_id=" & InsertedTransID & "' where date_completed is null and sercontract_id="& strContractID & " and DATEDIFF(dd,task_due_date,'" & strProcDate & "')<=14"


    I am trying to add an extra column to the update, but not sure if the syntax is correct.

    If Statement Issue



    This is very strange to me. I have spent 2hrs looking into this inside out , but dont seem to get it

    I have an if statement that inserts data into the database. But i check to make sure the name is not entered twice. Now when the name is already in the db, then it should insert else put out a message saying its already in the db

    My code works fine except that  when its not in the db, its inserts but still puts out the message that says "Name is already in use" Not sure if am not seeing something. But thought i did bring it to the forum. Here is my code...Pretty simple

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click

            Dim objConnection As SqlConnection
            Dim objCommand As SqlCommand
            Dim strSQLQuery1 As String


            ' If there's nothing to Add for then don't search
            ' o/w build our SQL Query and execute it.
            If String.IsNullOrEmpty(txtAdd.Text) Or Leadbank.SelectedValue = "000" Then


    statement cannot appear outside of a method body


    hi all,

      i am posting my vb.net problem .plz tell me how to resolve this :-

    Dim conn As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
        'Dim mysqlconnection As New SqlConnection(conn)
        'If mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();
        'Dim mySqlcommand As New SqlCommand("select CategoryId,CategoryName from Categories", mysqlconnection)
        'Dim mySqlDataAdapter As New SqlDataAdapter(mySqlcommand)
        'Dim mydataSet As New DataSet()

        'if mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();

    i m getting 5 errors in this code

    declaration expected in mySqlDataAdapter.Fill method; Gridview1.DataSource=ds; Gridview1.DataBind();

    how to multiple condition in if statement in asp.net C#



    i am using if condition to find out a time

    if(time=="08 AM)


    response.write"shift A";


    but problem is how can i put multiple condition in if like

    if(time=="06 AM" and "08 AM" and "07 AM")



    Hello, i need help changing the following code into a switch...case statementUndecided

    <script runat="server">
    void Page_Load()
        if (Page.IsPostBack)
        public String toSring()
        int intcomputerChoice=1;
           if (Page.IsPostBack)

    Using a If Else Statement


    I'm working in a Wizard control and need a little help. I'm pulling in a labels text through a databound field and if it equals a certain text then I need a textbox field to be less than or equal to a certain amount. I would also like to have a message appear to prompt the user that an invalid number has been entered. I'm not sure how to go about this. Is it better to use client side javascript or use page load and perform some kind of control validation. The code I've tried isn't working so any help would be greatly appreciated.

    For instance...

    Protected Sub Page_Load(ByVal Sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If label1 = "Refrigerator" then

    TextBox1 <= "700"

    Else Label1 = "Washer" then

    TextBox1 <= "500"

    End if

    End Sub

    How to set session timeout and clear session in asp.net C# ? And kill session when close the web app


    hi ,

    How to set session timeout and clear session in web.config and login.aspx  ? And when we close the web application , the session must be cleared ?

    I have use session.abandon as per below but is not working . Pls advise .


            protected void btnLogout_Click(object sender, EventArgs e)



    ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
    Sql Server  SharePoint  Silverlight  Others  All   

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend