使用SQL-DMO:
References: Microsoft SQLDMO Object LibraryOption ExplicitPrivate Sub Command1_Click()
Dim oSQLServer As New SQLDMO.SQLServer
Dim oDatabase As New SQLDMO.Database
Dim oDBFileData As New SQLDMO.DBFile
Dim oLogFile As New SQLDMO.LogFile
oSQLServer.LoginSecure = True '使用NT认证
oSQLServer.Connect "sz09"
oDatabase.Name = "Testing"
oDBFileData.Name = "DB1"
oDBFileData.PhysicalName = "D:\SQLXML\1.mdf"
oDBFileData.PrimaryFile = True
oDBFileData.FileGrowthType = SQLDMOGrowth_MB
oDBFileData.FileGrowth = 1
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
oLogFile.Name = "Log1"
oLogFile.PhysicalName = "D:\SQLXML\1.ldf"
oDatabase.TransactionLog.LogFiles.Add oLogFile
oSQLServer.Databases.Add oDatabase oSQLServer.DisConnect
End Sub
References: Microsoft SQLDMO Object LibraryOption ExplicitPrivate Sub Command1_Click()
Dim oSQLServer As New SQLDMO.SQLServer
Dim oDatabase As New SQLDMO.Database
Dim oDBFileData As New SQLDMO.DBFile
Dim oLogFile As New SQLDMO.LogFile
oSQLServer.LoginSecure = True '使用NT认证
oSQLServer.Connect "sz09"
oDatabase.Name = "Testing"
oDBFileData.Name = "DB1"
oDBFileData.PhysicalName = "D:\SQLXML\1.mdf"
oDBFileData.PrimaryFile = True
oDBFileData.FileGrowthType = SQLDMOGrowth_MB
oDBFileData.FileGrowth = 1
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
oLogFile.Name = "Log1"
oLogFile.PhysicalName = "D:\SQLXML\1.ldf"
oDatabase.TransactionLog.LogFiles.Add oLogFile
oSQLServer.Databases.Add oDatabase oSQLServer.DisConnect
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货