<%
Creating ************************ using the Adodb.connect 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 Two:
<%@ Language=vbscript%>
<%
Using the SQLDMO Object library *******************
Dim oSQLServer
Dim oDataBase
Dim Odbfiledata
Dim Ologfile
Dim Sdatabasename
Dim Sdatapath
Database name
Sdatabasename = "Codecreatedbtest"
Data File Save path
Sdatapath = "D:\"
Create a SQL Server object and link to it (local) as the server name
Set oSQLServer = Server.CreateObject ("SQLDMO. SQL Server ")
Osqlserver.loginsecure = True Using Integrated authentication integrated security
Osqlserver.connect "(local)"
Osqlserver.connect "(local)", "sa", "" "using standard validation standard security
Create a Database object
Set odatabase = Server.CreateObject ("SQLDMO. Database ")
Odatabase.name = Sdatabasename
To 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 With
To create a log file object
Set ologfile = Server.CreateObject ("SQLDMO. LogFile ")
With Ologfile
. Name = sdatabasename & "_log"
. PhysicalName = Sdatapath & "\" & Sdatabasename & "_log.ldf"
End With
To add DB file objects and log file objects to a database object
Odatabase.filegroups ("PRIMARY"). Dbfiles.add Odbfiledata
ODATABASE.TRANSACTIONLOG.LOGFILES.ADD Ologfile
To add a database to SQL Server (create the databases)
OSQLServer.Databases.Add oDataBase
Close connection
Osqlserver.close
Releasing objects
Set Ologfile = Nothing
Set Odbfiledata = Nothing
Set odatabase = Nothing
Set oSQLServer = Nothing
%>