谢谢版主对我的回答,但用ADOX中的CREATE只能建ACCESS库,我找了个建SQL SERVER库的,写出来希望有用_QQGB.
2007-11-11 10:22:47 来源:WEB开发网核心提示:<%'*这是方法一Dim oConn Dim sDatabaseName sDatabaseName = "test1"set oconn=server.CreateObject ("adodb.connection")oConn.Open "Provid
<%
'*********************************这是方法一
Dim oConn
Dim sDatabaseName
sDatabaseName = "test1"
set oconn=server.CreateObject ("adodb.connection")
oConn.Open "Provider=SQLOLEDB;Data Source=you_server;User ID=sa;Password=you_sa_password;"
oConn.Execute "CREATE DATABASE " & sDatabaseName
oConn.Close
set oconn=nothing
'*********************************方法一结束
'*********************************这是方法二
Dim oSQLServer
Dim oDatabase
Dim oDBFileData
Dim oLogFile
Dim sDatabaseName
Dim sDatapath
sDatabaseName = "test1"
'下面改成你的sql server(WINDOWS平台上强大的数据库平台)数据目录
sDatapath = "C:\Program Files\Microsoft sql server(WINDOWS平台上强大的数据库平台)\mssql(WINDOWS平台上强大的数据库平台)\Data"
' Create a new sql server(WINDOWS平台上强大的数据库平台) object and connect
Set oSQLServer = server.CreateObject ("SQLDMO.SQLServer")
' oSQLServer.LoginSecure = True
' Use integrated security
' oSQLServer.Connect "(local)"
oSQLServer.Connect "you_server", "sa", "you_sa_passwrod" ' Use standard security
' Create a server.CreateObject (" Database object
Set oDatabase = server.CreateObject ("SQLDMO.Database")
oDatabase.Name = sDatabaseName
' Create a server.CreateObject (" DB File object
Set oDBFileData = server.CreateObject ("SQLDMO.DBFile")
With oDBFileData
.Name = sDatabaseName & "_data"
.PhysicalName = sDatapath & "\" & sDatabaseName & "_data.mdf"
.Prima(最完善的虚拟主机管理系统)ryFile = True
.FileGrowthType = SQLDMOGrowth_MB
.FileGrowth = 1
End With
' Create a server.CreateObject (" LogFile object
Set oLogFile = server.CreateObject ("SQLDMO.LogFile")
With oLogFile
.Name = sDatabaseName & "_log"
.PhysicalName = sDatapath & "\" & sDatabaseName & "_log.ldf"
End With
' Add the DB File and Log file to the database object
oDatabase.FileGroups("Prima(最完善的虚拟主机管理系统)RY").DBFiles.Add oDBFileData
oDatabase.TransactionLog.LogFiles.Add oLogFile
' Add the database to sql server(WINDOWS平台上强大的数据库平台) (create the database)
oSQLServer.Databases.Add oDatabase
' Close the connection
oSQLServer.Close
' Clean Up
Set oLogFile = Nothing
Set oDBFileData = Nothing
Set oDatabase = Nothing
Set oSQLServer = Nothing
'**************************************方法二结束
%>
更多精彩
赞助商链接