Results 1 to 4 of 4

Thread: vbs file error with database...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83

    vbs file error with database...

    I just started learning about database's, and downloaded a vbs file from the website of the book I'm learning from. But when I run the vbs file to connect(?) the mdf and ldf files I get an error:

    ActiveX component cant create object. Can someone take a look at the code and see whats going on? Or maybe I didnt do something right....

    When it talks about my "sa" password is that my XP logon pass?
    Both files are in the same dir. I have access 2002, but Im not sure about sql.

    Code:
    '*********************************************************
    ' Purpose: Attaches the CD database to your SQL Server or 
    '          MSDE Database. 
    '
    ' Inputs:  Requires that CD.mdf and CD.ldf are in the same
    '          folder and that the correct password for the "sa"
    '          account is entered in this file.
    '
    ' Result:  If Attach of DB succeeds, cd.mdf and cd.ldf will
    '          not move, but they will be associated with your
    '          local SQL or MSDE database
    '*********************************************************
    
    'Change this line if your "sa" account does not have
    'a blank password.
    Const SA_PASSWORD = ""
    
    Dim sPath
    
    
    
    
    sPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
    
    mdfPath = sPath & "cd.mdf"
    ldfPath = sPath & "cd.ldf"
    
    Dim fso
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    If fso.FileExists(mdfPath) Then
    
    	If fso.FileExists(ldfPath) Then
    
    	   On Error Resume Next
      	   Dim oSvroot
       	   Set oSvroot = CreateObject("SQLDMO.SQLServer")
    	   If Err.Number <> 0 Then
    		WScript.Echo "Error: " & Err.Description
    		WScript.Quit
    	   End If
    
    	   oSvroot.Connect "(local)", "sa", SA_PASSWORD
    
    	   If Err.Number <> 0 Then
    		WScript.Echo "Error: " & Err.Description
    		WScript.Quit
    	   End If
    
    	   oSvroot.AttachDB "CD", "[" & mdfPath & "],[" & ldfPath & "]"
    
    	   If Err.Number <> 0 Then
    		WScript.Echo "Error: " & Err.Description
    		WScript.Quit
    	   Else
     	   	WScript.Echo "Attachment of CD database has completed successfully!"
    	   End If
    
    	Else
    
    	   WScript.Echo "LDF File not found at " & ldfPath
    	   WScript.Quit
    
    	End If
    
    Else
    
       Wscript.Echo "MDF File not found at " & mdfPath
       WScript.Quit
    
    End If
    
    
    WScript.Quit
    
    AttachError:
    
    	WScript.Echo "There has been an Error: " & Err.Description
    
    	WScript.Quit
    12/32/84 - I need some code to make me a sandwhich.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Well this doesnt look to be a .NET question but your problem is that code is for use with the MSSQL Desktop engine. It is basically a light version of SQL. Access 2000 is not what it is for.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Colorado
    Posts
    83
    Thanks for the help. I figured I needed sql. The reason I posted it here, was because the code I use to connect to the database is written in .NET, but your right it is off topic. - Sorry.
    12/32/84 - I need some code to make me a sandwhich.

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    no problem...you dont need the full sql for this code..just msde..you can find it for free at microsoft.com
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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