string _Server,_UserID,_Passwd,_BuildSQL,_SqlPath ,_dbname
long _BL,_Ifexist
_Bl = 1
_Server = sle_1.text///////////服务器名称
_UserID = sle_2.text///////////用户名称
_Passwd = sle_3.text///////////用户口令
_dbname = sle_4.text///////////数据库名称
if _Server='' or _UserID='' or _dbname='' or sle_5.text='' then
Messagebox("提示","请填入相应信息")
return
else
if _BL = 1 then
//连接sqlserver的master库
SQLCA.DBMS ='MSS Microsoft SQL Server 6.x'
SQLCA.Database ='Master'
SQLCA.LogID =_UserID
SQLCA.LogPass =_Passwd
SQLCA.ServerName =_Server
// SQLCA.AutoCommit = False
SQLCA.AutoCommit = true/////默认情况
connect;
if sqlca.sqlcode <> 0 then
messagebox('提示信息','服务器连接错误!')
_BL = 0
end if
end if
//判断库是否已经存在
if _BL = 1 then
select count(*) into :_Ifexist from sysdatabases where name = :_Dbname;
if _IFExist > 0 then
messagebox('提示信息','数据库已经存在!')
_BL = 0
end if
end if
//建库
if _Bl = 1 then
// _BuildSQL="RESTORE DATABASE "+_dbname+" FROM DISK =C:\MSSQL7\BACKUP\JxcEf_b.bak"
EXECUTE IMMEDIATE :_BuildSQL;
if sqlca.sqlcode = 0 then
//建立表结构
_BuildSQL = 'osql -S'+_Server + ' -U'+_UserID+' -P'+_Passwd+' -d'+_dbname+' -i'+sle_5.text
run(_BuildSQL,normal!)
////////////////////
commit;
messagebox('提示信息','建库成功!')
disconnect;
close(parent)
end if
else
disconnect;
end if
end if