Results 1 to 8 of 8

Thread: Not able to drop database after opening datatable

  1. #1

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Not able to drop database after opening datatable

    Hi everybody,

    I am using VB Webforms as my front end and MSDE 2000 as my back end. I am not able to drop a database after executing the following vb code on that database:

    VB Code:
    1. Dim vConnection As New SqlConnection(vConnectionString)
    2.         Dim vAdapter As New SqlDataAdapter("SELECT party_type_code, party_type_name, party_type_imported" & _
    3.                                             " FROM Party_Type" & _
    4.                                             " ORDER BY party_type_name", vConnection)
    5.         Dim vDataTable As New DataTable()
    6.         vAdapter.Fill(vDataTable)
    7.         vAdapter.Dispose()
    8.         vConnection.Dispose()

    On trying to drop the database using the SQL Command "DROP DATABASE PPCABCD2005", I get the error message:
    Cannot drop the database 'PPCABCD2005' because it is currently in use ...
    However, if I don't execute the above code, I am able to drop it. Why is it so? What is the solution to this problem?
    It is easy when you know it.

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Not able to drop database after opening datatable

    try:
    VB Code:
    1. vConnection.Close
    2. vConnection.Dispose()
    3. vConnection = Nothing
    Think it's the .Close bit that you need.

    Woof

  3. #3

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Re: Not able to drop database after opening datatable

    Thanks Wokawidget. I tried the code you suggested, but that did not work. Still I am not able to drop the database.
    It is easy when you know it.

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Not able to drop database after opening datatable

    Hmmm...I know this will make your app not work...but just try:
    VB Code:
    1. vDataTable.Dispose
    2. vDataTable = Nothing
    add that after you toast the connection object in the above code.

    Woka

  5. #5

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Re: Not able to drop database after opening datatable

    Hmmm...I know this will make your app not work...but just try:

    visual basic code:--------------------------------------------------------------------------------
    vDataTable.Dispose
    vDataTable = Nothing
    --------------------------------------------------------------------------------
    add that after you toast the connection object in the above code.
    I tried this too. Still I am getting the same error message.
    It is easy when you know it.

  6. #6
    Member
    Join Date
    Jan 2003
    Location
    Bangalore
    Posts
    47

    Re: Not able to drop database after opening datatable

    Try this


    vConnection.Close
    vConnection.Dispose()
    vConnection = Nothing
    Sleep 2000

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: Not able to drop database after opening datatable

    .Net uses connection pooling... its quite possible the connection is still alive, even if you dispose a reference to it within your assembly.

    Open Enterprise Manager and look for the Management folder...

    Open the Current Activity.. Process Info.



    Look for your database... and see what connections may be active (by looking in the Status column).
    Attached Images Attached Images  

  8. #8

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Re: Not able to drop database after opening datatable

    Thanks
    It is easy when you know it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width