Two methods for creating SQL Server databases using ASP

Source: Internet
Author: User

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

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.