Results 1 to 4 of 4

Thread: HOW TO: Delete a SQL 7.0 database?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    136

    HOW TO: Delete a SQL 7.0 database?

    Hello there,

    Does anybody knows how to delete a SQL Server 7.0 or MSDE database using VB. Pls show me some codes..

    actually i do have d codes but it only works on SQL 2000
    heres d code. (pls try to debug what is wrong)


    Dim objRoot As Object
    Set objRoot = CreateObject("SQLDMO.SQLServer")

    objRoot.LoginTimeout = 60
    objRoot.Connect "(local)", user, password
    Call objRoot.KillDatabase("MyDatabase")

    tried it on MSDE and SQL 7.0
    it generates an error #2702-database do not exist

    Your help is very much appreciated.
    elbimbo

  2. #2
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    You will want to connect to a different database than the one you are dropping.
    VB Code:
    1. Dim oConn As Connection
    2. Dim ConStr As String
    3. Dim sSql As String
    4.  
    5. sSql = "Drop Database myDB"
    6.  
    7. ConStr = "Provider=SQLOLEDB.1;" & _
    8.                "Server=myServ;" & _
    9.                "Initial Catalog=master;" & _
    10.                "UID=" & sUID & ";" & _
    11.                "PWD=" & sPWD & ";"
    12.  
    13. Set oConn = New Connection
    14. With oConn
    15.     .CursorLocation = adUseClient
    16.     .CommandTimeout = 10
    17.     .Open ConStr
    18.  
    19.     .Execute sSql
    20.     .Close
    21. End With
    22.  
    23. Set oConn = Nothing
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  3. #3
    Junior Member prashx's Avatar
    Join Date
    Jul 2002
    Location
    chEnnai
    Posts
    30

    Smile

    I wonder if elbimbo forgot to mod. these lines!

    objRoot.Connect "(local)", user, password
    Call objRoot.KillDatabase("MyDatabase")

    ..

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2001
    Location
    Philippines
    Posts
    136

    I solve it myself

    Thanks a lot guys.

    I solve it my self. My codes works on SQL 2000 and to make it work to MSDE or SQL 7.0 you must use:

    objRoot.databases.remove([index],[owner])

    thats it. (this code will work both on SQL 7.0 and 2000)

    You guys continue helping those who needs our expertise.

    until then...

    Elbimbo
    elbimbo

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