最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ASP创建SQL Server数据库的两种方法
时间:2022-06-30 10:43:28 编辑:袖梨 来源:一聚教程网
<%
************ 使用ADODB.Connect对象创建 ************************
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
%>
方法二:
<%@ Language=VBScript %>
<%
******************* 使用 SQLDMO Object 对象库 *******************
Dim oSQLServer
Dim oDatabase
Dim oDBFileData
Dim oLogFile
Dim sDatabaseName
Dim sDatapath
数据库名字
sDatabaseName = "CodeCreateDBTest"
数据文件保存路径
sDatapath = "D:"
创建Sql Server对象并进行链接,(local)处为Server名字
Set oSQLServer = Server.CreateObject("SQLDMO.SQLServer")
oSQLServer.LoginSecure = True 使用集成验证integrated security
oSQLServer.Connect "(local)"
oSQLServer.Connect "(local)", "sa", "" 使用标准验证 standard security
创建Database对象
Set oDatabase = Server.CreateObject("SQLDMO.Database")
oDatabase.Name = sDatabaseName
创建db文件对象
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
创建日志文件对象
Set oLogFile = Server.CreateObject("SQLDMO.LogFile")
With oLogFile
.Name = sDatabaseName & "_log"
.PhysicalName = sDatapath & "" & sDatabaseName & "_log.ldf"
End With
把DB文件对象和日志文件对象添加到DataBase数据库对象
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
oDatabase.TransactionLog.LogFiles.Add oLogFile
把数据库添加到Sql server(create the database)
oSQLServer.Databases.Add oDatabase
关闭连接
oSQLServer.Close
释放对象
Set oLogFile = Nothing
Set oDBFileData = Nothing
Set oDatabase = Nothing
Set oSQLServer = Nothing
%>
************ 使用ADODB.Connect对象创建 ************************
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
%>
方法二:
<%@ Language=VBScript %>
<%
******************* 使用 SQLDMO Object 对象库 *******************
Dim oSQLServer
Dim oDatabase
Dim oDBFileData
Dim oLogFile
Dim sDatabaseName
Dim sDatapath
数据库名字
sDatabaseName = "CodeCreateDBTest"
数据文件保存路径
sDatapath = "D:"
创建Sql Server对象并进行链接,(local)处为Server名字
Set oSQLServer = Server.CreateObject("SQLDMO.SQLServer")
oSQLServer.LoginSecure = True 使用集成验证integrated security
oSQLServer.Connect "(local)"
oSQLServer.Connect "(local)", "sa", "" 使用标准验证 standard security
创建Database对象
Set oDatabase = Server.CreateObject("SQLDMO.Database")
oDatabase.Name = sDatabaseName
创建db文件对象
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
创建日志文件对象
Set oLogFile = Server.CreateObject("SQLDMO.LogFile")
With oLogFile
.Name = sDatabaseName & "_log"
.PhysicalName = sDatapath & "" & sDatabaseName & "_log.ldf"
End With
把DB文件对象和日志文件对象添加到DataBase数据库对象
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
oDatabase.TransactionLog.LogFiles.Add oLogFile
把数据库添加到Sql server(create the database)
oSQLServer.Databases.Add oDatabase
关闭连接
oSQLServer.Close
释放对象
Set oLogFile = Nothing
Set oDBFileData = Nothing
Set oDatabase = Nothing
Set oSQLServer = Nothing
%>
相关文章
- 《潜行者2:切尔诺贝利之心》游戏车辆使用推荐 11-22
- 《潜行者2:切尔诺贝利之心》挡路的特异点处理方法介绍 11-22
- 《潜行者2:切尔诺贝利之心》开局获得满强AK方法介绍 11-22
- 《潜行者2:切尔诺贝利之心》军用防弹背心获得方法介绍 11-22
- 《潜行者2:切尔诺贝利之心》防毒面具获得方法介绍 11-22
- 《潜行者2:切尔诺贝利之心》开局捡尸体摸尸注意事项分享 11-22