ASP建立SQL Server資料庫的兩種方法

來源:互聯網
上載者:User
server|建立|資料|資料庫 <%
************ 使用ADODB.Connect對象建立 ************************
Dim oConn
Dim sDatabaseName
sDatabaseName = "CodeCreateDB"
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=SQLOLEDB;Data Source=(local);User ID=sa;Password=;"
oConn.Execute "CREATE DATABASE " & sDatabaseName
%>



方法二:

<%@ Language=VBScript %>
<%
******************* 使用 SQLDMO Object 物件程式庫 *******************
Dim oSQLServer
Dim oDatabase
Dim oDBFileData
Dim oLogFile
Dim sDatabaseName
Dim sDatapath

資料庫名字
sDatabaseName = "CodeCreateDBTest"
資料檔案儲存路徑
sDatapath = "D:\"

建立Sql Server對象並進行連結,(local)處為Server名字
Set oSQLServer = Server.CreateObject("SQLDMO.SQLServer")
oSQLServer.LoginSecure = True 使用整合驗證integrated security
oSQLServer.Connect "(local)"
oSQLServer.Connect "(local)", "sa", "" 使用標準驗證 standard security

建立Database對象
Set oDatabase = Server.CreateObject("SQLDMO.Database")
oDatabase.Name = sDatabaseName

建立db檔案對象
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

建立記錄檔對象
Set oLogFile = Server.CreateObject("SQLDMO.LogFile")
With oLogFile
.Name = sDatabaseName & "_log"
.PhysicalName = sDatapath & "\" & sDatabaseName & "_log.ldf"
End With

把DB檔案對象和記錄檔對象添加到DataBase資料庫物件
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
oDatabase.TransactionLog.LogFiles.Add oLogFile

把資料庫添加到Sql server(create the database)
oSQLServer.Databases.Add oDatabase

關閉串連
oSQLServer.Close

釋放對象
Set oLogFile = Nothing
Set oDBFileData = Nothing
Set oDatabase = Nothing
Set oSQLServer = Nothing
%>




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.