程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> ADOX中的CREATE只能建ACCESS庫,我找了個建SQL SERVER庫的

ADOX中的CREATE只能建ACCESS庫,我找了個建SQL SERVER庫的

編輯:關於SqlServer

<%
'*********************************這是方法一
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數據目錄
sDatapath = "C:Program FilesMicrosoft SQL ServerMSSQLData"


' Create a new SQL Server 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"
    .PrimaryFile = 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("PRIMARY").DBFiles.Add oDBFileData
oDatabase.TransactionLog.LogFiles.Add oLogFile

' Add the database to SQL Server (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
'**************************************方法二結束

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved