ASP Create two ways to create a SQL Server database
method one:
<% '*********** Create ******************************************************* = " 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 SqldMo Object Object Library ************** **** DIM OSQLServerdim OdatabaseDim OdbfileDataDim Ologfiledim SDatabaseNamedim SDataPath
'Database Name SDATABASENAME = "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
'Creating a Database object set odatabase = server.createObject ("sqldmo.database") odatabase.name = SDATABASENAME
'Create db file objects Set oDBFileData = Server.CreateObject ( "SQLDMO.DBFile") With oDBFileData .Name = sDatabaseName & "_data" .PhysicalName = sDatapath & "/" & sDatabaseName & "_data.mdf" .PrimaryFile = True .FileGrowthType = Sqldmogrowth_mb .filegrowth = 1END with
'Creating a log file object set ologfile = server.createObject ("sqldmo.logfile") with ologfile .name = sdatabaseName & "_log" .physicalname = sdataPath & "& sdatabaseName &" _log.ldf "End with
'DB file objects and to add objects to the log file database object DataBase oDatabase.FileGroups ( "PRIMARY"). DBFiles.Add oDBFileDataoDatabase.TransactionLog.LogFiles.Add oLogFile' to add to the database Sql server (create the database) oSQLServer.Databases. Add Odatabase
'Close connection OSQLSERVER.CLOSE
'Release Object Set Ologfile = NothingSet ODATABASE = NothingSet ODatabase = NothingSet OSQLServer = Nothing%>