Two ways for ASP to create SQL Server databases

Source: Internet
Author: User
Tags connect create database

<%
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
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.