<%
* *********** Use ADODB. create a connection object ************************
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
%>
Method 2:
<% @ Language = VBScript %>
<%
* ***************** Use the sqldmo Object Library **************** ***
Dim osqlserver
Dim odatabase
Dim odbfiledata
Dim ologfile
Dim sdatabasename
Dim sdatapath
Database Name
Sdatabasename = "codecreatedbtest"
Data File Storage path
Sdatapath = "D :/"
Create and link an SQL Server object. The local object is named "server ".
Set osqlserver = server. Createobject ("sqldmo. sqlserver ")
Osqlserver. loginsecure = true use integration to verify Integrated Security
Osqlserver. Connect "(local )"
Osqlserver. Connect "(local)", "sa", "" use standard verification standard security
Create a database object
Set odatabase = server. Createobject ("sqldmo. Database ")
Odatabase. Name = sdatabasename
Create a 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
Create a log file object
Set ologfile = server. Createobject ("sqldmo. logfile ")
With ologfile
. Name = sdatabasename & "_ log"
. Physicalname = sdatapath & "/" & sdatabasename & "_ log. LDF"
End
Add the DB file object and log file object to the database object
Odatabase. filegroups ("primary"). dbfiles. Add odbfiledata
Odatabase. transactionlog. logfiles. Add ologfile
Add a database to SQL Server (create the database)
Osqlserver. Databases. Add odatabase
Close connection
Osqlserver. Close
Release object
Set ologfile = nothing
Set odbfiledata = nothing
Set odatabase = nothing
Set osqlserver = nothing
%>