PDA

Click to See Complete Forum and Search --> : vbs file error with database...


Jes|er
Feb 28th, 2002, 08:22 PM
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.



'*********************************************************
' 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

Cander
Mar 1st, 2002, 08:25 AM
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.

Jes|er
Mar 1st, 2002, 08:41 AM
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. :)

Cander
Mar 1st, 2002, 08:44 AM
no problem...you dont need the full sql for this code..just msde..you can find it for free at microsoft.com