0
我曾經使用SQL-DMO在VBS中運行腳本來創建新數據庫。這是爲SQL Server 2000完成的,但是這不再適用於SQL Server 2008 R2。使用VBS創建SQL Server 2008 R2數據庫時出錯(SQL DMO)
腳本是這樣的:
Const C_SQL_UID = "sa"
Const C_SQL_PWD = "sa"
Const C_SQL_SERVER = "dbserver"
Const C_SQL_TMPDBNAME = "TMP_DB"
Const C_SQLDIR = "d:\data"
Dim SqlServer: Set SqlServer = CreateObject("SQLDMO.SqlServer")
SqlServer.Connect C_SQL_SERVER, C_SQL_UID, C_SQL_PWD
Dim database: Set database = CreateObject("SQLDMO.Database")
Dim dbDataFile: Set dbDataFile = CreateObject("SQLDMO.DBFile")
Dim dbLogFile: Set dbLogFile = CreateObject("SQLDMO.LogFile")
database.Name = C_SQL_TMPDBNAME
dbDataFile.Name = C_SQL_TMPDBNAME
dbDataFile.PhysicalName = C_SQLDIR & "\" & C_SQL_TMPDBNAME & "_Data.mdf"
dbDataFile.PrimaryFile = True
dbDataFile.Size = 2
dbDataFile.FileGrowthType = 0 'SQLDMOGrowth_MB
dbDataFile.FileGrowth = 1
database.FileGroups.Item("PRIMARY").DBFiles.Add(dbDataFile)
dbLogFile.Name = C_SQL_TMPDBNAME & "Log"
dbLogFile.PhysicalName = C_SQLDIR & "\" & C_SQL_TMPDBNAME & "_Log.ldf"
dbLogFile.Size = 2
database.TransactionLog.LogFiles.Add(dbLogFile)
On Error Resume Next
SqlServer.Databases.Add(database)
If Err Then
wscript.echo Now & " Error creating DB (" & Err.Number & ") " & Err.Description
End If
On Error GoTo 0
當執行最後的指令(「SqlServer.Databases.Add(數據庫)」),我得到的錯誤號-2147219701 ...不包含任何描述。我不確定它可以從哪裏來。 我知道微軟放棄了DMO的事情,但由於SMO不支持VBScript,所以我沒有選擇。
任何想法?