📄 msde_attachnorthwind.vbs
字号:
' This script attaches a Northwind database to the default MSDE instance
' (local)\VSDOTNET in Visual Studio .NET
' robert
Option Explicit
On Error Resume Next
Dim oSQLDMO
Dim sServerName
Dim sDBName
Dim sDataFiles
Dim sTitle
Dim nAnswer
' Initialize strings
sServerName = "(local)\VSDOTNET"
sDBName = "nwind"
sDataFiles = "C:\adonetsbs\SampleDBs\northwnd.mdf, C:\adonetsbs\SampleDBs\Northwind_log.LDF"
sTitle = "MSDE_AttachNorthwind"
nAnswer = MsgBox("Do you want to try to attach the following database?" & VbCrLf & VbCrLf & _
"Server Name: " & sServerName & VbCrLf & _
"Database Name: " & sDBName & VbCrLf & _
"Data Files: " & sDataFiles & VbCrLf, _
vbYesNo + vbQuestion, sTitle)
If nAnswer = vbYes Then
' Create SQLDMO.SQLServer object
Set oSQLDMO = WScript.CreateObject("SQLDMO.SQLServer")
If Err <> 0 Then
Call PrintError("Unable to create SQLDMO.SQLServer object.")
End If
If Not(oSQLDMO Is Nothing) Then
' Connect
oSQLDMO.LoginSecure = True
oSQLDMO.Connect(sServerName)
If Err <> 0 Then
Call PrintError("Unable to connect to " & sServerName)
Else
' Attach
Call oSQLDMO.AttachDB(sDBName, sDataFiles)
If Err <> 0 Then
Call PrintError("Unable to attach " & sDBName & " database." & VbCrLf & sDataFiles)
End If
End If
Set oSQLDMO = Nothing
End If
If Err = 0 Then
Call MsgBox(sDBName & " database should be attached to " & sServerName & ".", _
vbInformation , sTitle)
Else
Call PrintError("An error occurred.")
End If
End If
Sub PrintError(sError)
Call MsgBox(sError & " " & VbCrLf & VbCrLf & _
"Error Number: " & Err.Number & VbCrLf & _
"Error Description: " & Err.Description, vbCritical, sTitle)
WScript.Quit
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -