ASP Create two ways to create a SQL Server database

xiaoxiao2021-03-06  41

<% ************ Create ************************************************** = "CodeCreatedB using AdoDb.Connect object "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%> <% ************************************************************************ *** Dim Osqlserverdim Odatabasedim OdbfileDataDim Ologfiledim SDatabaseNamedim SDataPath

Database name sdatabaseename = "codecreatedbtest" Data file save path SDATAPATH = "D: /"

Sql Server object and create a link, (local) for the Server name at Set oSQLServer = Server.CreateObject ( "SQLDMO.SQLServer") oSQLServer.LoginSecure = True use integrated authentication 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 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 = 1END with

Create log file object set ologfile = server.createObject ("sqldmo.logfile") with ologfile .name = sdatabaseName & "_log" .physicalname = sdataPath & "& sdatabaseename &" _log.ldf "end with

Add the DB files and log files Objects DataBase objects to database objects oDatabase.FileGroups ( "PRIMARY"). DBFiles.Add oDBFileDataoDatabase.TransactionLog.LogFiles.Add oLogFile to add a database to Sql server (create the database) oSQLServer.Databases.Add oDatabase

Close connection OSQLServer.close

Release Object Set Ologfile = NothingSet ODATABASE = NothingSet ODatabase = NothingSet OSQLServer = Nothing%>

转载请注明原文地址:https://www.9cbs.com/read-78164.html

New Post(0)