跳到主要内容

关闭连接

命令说明

关闭数据库连接

命令原型

Database.CloseDB(objDatabase)

命令参数

参数必选类型默认值说明
objDatabaseTrueexpressionobjDatabase数据库对象,使用“创建数据库对象“命令(Database.CreateDB)创建的数据库对象

运行实例

/*********************************关闭连接***************************************
命令原型:
Database.CloseDB(objDatabase)
入参:
objDatabase--数据库对象,使用“创建数据库对象“命令(Database.CreateDB)创建的数据库对象
注意事项:
数据库连接使用完后记得及时关闭
连接命令的charset参数需要与服务端保持一致
**********************************************************************************/
Dim objDatabase
Dim ip,port,username,password,db

//*********************************MySQL***************************************
// 连接MySQL数据库
ip = "127.0.0.1"
port = "3306"
username = "root"
password = "rg+d2Wr8T+Dv10iQBk7VUw=="
db = "test"
objDatabase = Database.CreateDB("MySQL", {
"host": ip,
"port": port,
"user": username,
"password": password,
"database": db,
"charset": "utf8"
})
// 关闭数据库连接
Database.CloseDB(objDatabase)

//*********************************PostgreSQL***************************************
// 连接PostGreSQL数据库
ip = "127.0.0.1"
port = "5432"
username = "root"
password = "rg+d2Wr8T+Dv10iQBk7VUw=="
db = "postgres"
objDatabase = Database.CreateDB("PostgreSQL", {
"host": ip,
"port": port,
"user": username,
"password": password,
"database": db
})
// 关闭数据库连接
Database.CloseDB(objDatabase)

//*********************************Sqlite3***************************************
// 连接Sqlite3数据库
objDatabase = Database.CreateDB("Sqlite3", {"filepath": '''D:\工作文档\sqlite\test.db'''})
// 关闭数据库连接
Database.CloseDB(objDatabase)

//*********************************SQLServer***************************************
// 连接SQLServer数据库
ip = "127.0.0.1"
port = "1433"
username = "SA"
password = "rg+d2Wr8T+Dv10iQBk7VUw=="
db = "TestDB"
objDatabase = Database.CreateDB("PostgreSQL", {
"host": ip,
"port": port,
"user": username,
"password": password,
"database": db,
"charset": "utf8"
})
// 关闭数据库连接
Database.CloseDB(objDatabase)

//*********************************Oracle***************************************
// 连接Oracle数据库
ip = "127.0.0.1"
port = "1521"
username = "oracle"
password = "OvUZIny9qZUrgJE0ho2tnQ=="
service_name = ""
sid = "helowin"
objDatabase = Database.CreateDB("Oracle", {
"host": ip,
"port": port,
"user": username,
"password": password,
"service_name": service_name,
"sid": sid,
"charset": "utf8"
})
// 关闭数据库连接
Database.CloseDB(objDatabase)

可视化样例