Installshield 6 打包asp.net网站

来源:互联网 发布:mysql 某个字段加一 编辑:程序博客网 时间:2024/04/30 07:16

需求:
1.建立虚拟目录
2.建立iis独立站点
3.删除虚拟目录
4.附加数据库
5.分离数据库
//6.检测iis .net 是否安装
////////////////////////////////////////////////////////////////////////////////
//                                                                           
//  File Name: Setup.rul                                                  
//                                                                           
//  Description: InstallShield script                                       
//                                                                           
//  Comments: This script was generated based on the selections you made in
//            the Project Wizard.  Refer to the help topic entitled "Modify     
//            the script that the Project Wizard generates" for information
//    on possible next steps.
//
////////////////////////////////////////////////////////////////////////////////


// Include header files
   
#include "ifx.h"
   
////////////////////// string defines ////////////////////////////

//////////////////// installation declarations ///////////////////

// ----- DLL function prototypes -----
prototype CreateWebSite(STRING,STRING,STRING); // 创建 IIS 站点
prototype CreateVirtualDir(STRING); // 创建虚拟目录
prototype DeleteVirtualDir();//删除虚拟目录
prototype CreateDataBase(STRING,STRING,STRING);//创建SQL数据库
prototype DeCreateDataBase();//分离SQL数据库
prototype CheckIIS(); // 示例:检查系统是否安装IIS  
prototype connSQLDB(STRING,STRING,STRING);//连接数据库

 // your DLL function prototypes


// ---- script function prototypes -----


    // your script function prototypes

    // your global variables
    STRING TMP_PRODUCT_NAME,TMP_PRODUCT_VERSION,TMP_COMPANY_NAME,TMP_PRODUCT_KEY,TMP_TITLE_CAPTIONBAR;
    STRING nSetupType,szSQLsvr,szSQLusr,szSQLpwd,szSQLsvrDefault,szSQLusrDefault,szSQLpwdDefault;
    STRING svName, svCompany, svSerial;
    STRING globalstr,destdir,destsvr,destsa,destpw;
    STRING VirtualDirName;
    number svEdit1,svEdit2;
    string szServerIP,szServerPort,szServername,szServerdir,szServerIPDefault,szServerPortDefault,szServernameDefault,szServerdirDefault;
    BOOL iscreatedb;

 

//////////////////////////////////////////////////////////////////////////////
//                                                                          
//  FUNCTION:   OnFirstUIBefore                                           
//                                                                          
//  EVENT:      FirstUIBefore event is sent when installation is run for the first
//              time on given machine. In the handler installation usually displays
//              UI allowing end user to specify installation parameters. After this
//              function returns, ComponentTransferData is called to perform file
//              transfer.
//                                                                          
///////////////////////////////////////////////////////////////////////////////
function OnFirstUIBefore()
    number  nResult,nSetupType,nOpt;
    string  szTitle, szMsg;
    string  szLicenseFile, szQuestion;
    string  szName, szCompany, szSerial;
    string  szTargetPath;
    string  szDir;
    string  szField1,szField2;
    string  szComponents, szTargetdir;
    number  nLevel;
    LIST    listStartCopy;
    number  nvSize;
begin
 TMP_PRODUCT_NAME="天辰开放式基础教育资源管理系统";
    TMP_PRODUCT_VERSION="V5.0";
    TMP_COMPANY_NAME="天辰软件";
    TMP_PRODUCT_KEY="20070910";
    TMP_TITLE_CAPTIONBAR="0";
    // TO DO: if you want to enable background, window title, and caption bar title                                                                    
   // SetTitle( TMP_PRODUCT_NAME+"安装程序", 24, WHITE );                                       
    //SetTitle( TMP_PRODUCT_NAME+"安装程序", 0, BACKGROUNDCAPTION );                    
    // Enable( FULLWINDOWMODE );        
    // Enable( BACKGROUND );        
    // SetColor(BACKGROUND,RGB (0, 128, 128));
        
    nSetupType = TYPICAL; 
    TARGETDIR = PROGRAMFILES ^@COMPANY_NAME ^@PRODUCT_NAME
    szDir = TARGETDIR;
    szName    = "";
    szCompany = "";
    szSerial = "111-111111";
   
    if (CheckIIS()==1) then // 示例:检查系统是否安装IIS  
       goto Dlg_Start;
    else                                               
       MessageBox ("该系统没有安装IIS,请先安装IIS!",WARNING);
       abort;//结束安装
    endif;

Dlg_Start:
    // beginning of dialogs label

Dlg_SdWelcome:
    szTitle = "欢迎安装使用  "+TMP_PRODUCT_NAME+" "+TMP_PRODUCT_VERSION;;
    szMsg   = "";
    nResult = SdWelcome( szTitle, szMsg );
    if (nResult = BACK) goto Dlg_Start;

Dlg_SdLicense:
    szLicenseFile = SUPPORTDIR ^ "license.txt";
    szTitle    = "最终用户许可协议";
    szMsg      = "";
    szQuestion = "";
    nResult    = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile );
    if (nResult = BACK) goto Dlg_SdWelcome;

Dlg_SdRegisterUser:
    szMsg   = "";
    szTitle = "用户信息注册"; 
    nResult = SdRegisterUser( szTitle, szMsg, szName, szCompany );
    if (nResult = BACK) goto Dlg_SdLicense;

Dlg_SdAskDestPath:
    szTitle = "主程序安装位置";
    szMsg   = "";
    nResult = SdAskDestPath( szTitle, szMsg, szDir, 0 );
    TARGETDIR = szDir;
    if (nResult = BACK) goto Dlg_SdRegisterUser;

Dlg_ObjDialogs:
    nResult = ShowObjWizardPages(nResult);
    if (nResult = BACK) goto Dlg_SdAskDestPath;
   
Dlg_SelMode ://设置数据库服务器 对话框
  szTitle = "设置"+@PRODUCT_NAME+"的运行模式";
    szMsg = "请选择软件运行的方式,极力推荐使用虚拟目录方式运行";
    szField2="独立站点方式运行(Window服务版本)";
   szField1="虚拟目录方式运行(WindowXP以上)";
    svEdit1=TRUE;
    svEdit2=FALSE;
    SetDialogTitle(DLG_ASK_TEXT,szTitle);
    DialogSetInfo ( DLG_INFO_CHECKSELECTION, "", 1);
    nOpt = EXCLUSIVE ;
    nResult = AskOptions (nOpt,szMsg,szField1,svEdit1,szField2,svEdit2);
    if (nResult = BACK) goto Dlg_ObjDialogs;
   if (svEdit2=FALSE) goto Dlg_AskText1;
   
Dlg_AskText ://设置IIS站点 对话框
    szTitle = "设置IIS信息服务及数据库服务器";
    szMsg = "现在开始设置IIS系统";
    szQuestion="    请输入本服务器的IP地址和运行端口信息,安装程序将按照您提供的资料设置IIS信息服务。如果您没有填写,安装程序将自动跳过站点的创建!";
    szServerIP="地址:";
    szServerPort="端口:";
    szServerIPDefault="192.168.0.1";
    szServerPortDefault="80";
    SetDialogTitle(DLG_ASK_TEXT,szTitle);
    nResult=SdShowDlgEdit2 (szTitle, szQuestion,szServerIP,szServerPort,szServerIPDefault,szServerPortDefault);
    if (nResult = BACK) goto Dlg_SelMode;
    if (nResult = NEXT) goto Dlg_AskSQL;
   
Dlg_AskText1 ://设置IIS服务器,建立虚拟目录 对话框
    szTitle = "设置IIS信息服务器";
    szMsg = "现在开始设置IIS系统";
    szQuestion="    请输入虚拟目录的名称和路径(路径一般不需要更改),安装程序将按照您提供的资料设置IIS信息服务。如果您没有填写,安装程序将自动跳过站点的创建!";
    szServername="别名:";
    szServerdir="目录:"; 
    szServernameDefault="tcMidResource";
    szServerdirDefault=szDir;
    SetDialogTitle(DLG_ASK_TEXT,szTitle);
    nResult=SdShowDlgEdit2 (szTitle, szQuestion,szServername,szServerdir,szServernameDefault,szServerdirDefault);
    if (nResult = BACK) goto Dlg_SelMode; 
   
Dlg_AskSQL ://设置数据库服务器 对话框
    szTitle = "设置数据库";
    szMsg = "现在开始设置Microsoft SQL Server数据库系统";
    szQuestion=" 请输入SQL SERVER数据库服务器的用户名和密码,安装程序将按照您上步提供的IP地址和下面的用户名和密码创建和优化数据库系统。如果您提供的用户名和密码是错误的,安装程序将自动跳过数据的设置!";
    szSQLsvr="主机名:";
    szSQLusr="用户名:";
    szSQLpwd="密码:";
    szSQLsvrDefault="(local)";
    szSQLusrDefault="sa";
    szSQLpwdDefault="";
    SetDialogTitle(DLG_ASK_TEXT,szTitle);
    nResult=SdShowDlgEdit3 (szTitle,szQuestion,szSQLsvr,szSQLusr,szSQLpwd,szSQLsvrDefault,szSQLusrDefault,szSQLpwdDefault);
    if (nResult = BACK) goto Dlg_AskText1;   
    if connSQLDB(szSQLsvrDefault,szSQLusrDefault,szSQLpwdDefault)=FALSE  goto Dlg_AskSQL;
    
Dlg_SdStartCopy:
    szTitle = "请确认你所输入的信息";
    szMsg   = "点击下一步开始安装";
    listStartCopy = ListCreate( STRINGLIST );
    //The following is an example of how to add a string(szName) to a list(listStartCopy).
    //eg. ListAddString(listStartCopy,szName,AFTER);
    ListAddString(listStartCopy,"用户名:"+szName,AFTER);
    ListAddString(listStartCopy,"公司名称:"+szCompany,AFTER);
    ListAddString(listStartCopy,"目标目录:"+szDir,AFTER);
    if (svEdit2=TRUE) then
        ListAddString(listStartCopy,"IIS站点IP地址:"+szServerIPDefault,AFTER);
        ListAddString(listStartCopy,"IIS站点端口号:"+szServerPortDefault,AFTER);
    endif;                                          
    if (svEdit1=TRUE) then
        ListAddString(listStartCopy,"IIS虚拟目录别名:"+szServernameDefault,AFTER);
        ListAddString(listStartCopy,"IIS虚拟目录路径:"+szServerdirDefault,AFTER);
    endif;
    ListAddString(listStartCopy,"SQL数据库主机名:"+szSQLsvrDefault,AFTER);
    ListAddString(listStartCopy,"SQL数据库用户名:"+szSQLusrDefault,AFTER);
    ListAddString(listStartCopy,"SQL数据库密码:"+szSQLpwdDefault,AFTER);           
    ListAddString(listStartCopy,"",AFTER);                              
    ListAddString(listStartCopy,"请确认您填写的信息,按下一步开始安装",AFTER); 
   
    iscreatedb=TRUE;//安装数据库标志为真
    destsvr=szSQLsvrDefault;
    destsa=szSQLusrDefault;
    destpw=szSQLpwdDefault;
    nResult = SdStartCopy( szTitle, szMsg, listStartCopy ); 
    ListDestroy(listStartCopy);
    if (nResult = BACK) goto Dlg_AskSQL;

    // setup default status
    SetStatusWindow(0, "");
    Enable(STATUSEX);
    StatusUpdate(ON, 100); 
    return 0;
end;

///////////////////////////////////////////////////////////////////////////////
//
//  FUNCTION:   OnMoving
//
//  EVENT:      Moving event is sent when file transfer is started as a result of
//              ComponentTransferData call, before any file transfer operations
//              are performed.
//
///////////////////////////////////////////////////////////////////////////////
function OnMoving()
    string szAppPath,szSrcFile,szTargetPath;
begin
    // Set LOGO Compliance Application Path
    // TO DO : if your application .exe is in a subfolder of TARGETDIR then add subfolder
    szAppPath = TARGETDIR;
    RegDBSetItem(REGDB_APPPATH, szAppPath);
    RegDBSetItem(REGDB_APPPATH_DEFAULT, szAppPath ^ @PRODUCT_KEY);
   
    CreateDir (TARGETDIR^"midres");
    szSrcFile="//midres//*.*";
    szTargetPath=TARGETDIR^"midres";
    XCopyFile (szSrcFile, szTargetPath, INCLUDE_SUBDIR);
    SetStatusWindow(0, "");
    Enable(STATUSEX);
    StatusUpdate(ON, 100);
end;
 
///////////////////////////////////////////////////////////////////////////////
//
//  FUNCTION:   OnFirstUIAfter
//
//  EVENT:      FirstUIAfter event is sent after file transfer, when installation
//              is run for the first time on given machine. In this event handler
//              installation usually displays UI that will inform end user that
//              installation has been completed successfully.
//
///////////////////////////////////////////////////////////////////////////////
function OnFirstUIAfter()
    STRING szTitle,szMsg, szMsg1, szMsg2, szOption1, szOption2,szFileNa,szKey,szTargetPath,szSrcFile;
    NUMBER bOpt1, bOpt2;
    STRING sztemp1,sztemp2,sztemp3;
begin 
    //安装路径
    if (RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE)< 0)   then
       MessageBox("注册表写入失败!",   SEVERE);
    endif;
    szKey="//Software//Microsoft//tcmidres";
    if RegDBKeyExist(szKey)< 0   then
        RegDBCreateKeyEx(szKey,"");
    endif;
    RegDBSetKeyValueEx(szKey,"respath",REGDB_STRING,TARGETDIR,1); 
   
    if (RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE)< 0)   then
       MessageBox("注册表写入失败!",   SEVERE);
    endif;
    szKey="//Software//Microsoft//tcmidres1";
    if RegDBKeyExist(szKey)< 0   then
        RegDBCreateKeyEx(szKey,"");
    endif;
    RegDBSetKeyValueEx(szKey,"respath1",REGDB_STRING,TARGETDIR,1);
   
     CreateDir (WINSYSDISK^"//Inetpub//wwwroot//webctrl_client");
    szSrcFile=TARGETDIR^"webctrl_client//*.*";
    szTargetPath=WINSYSDISK^"//Inetpub//wwwroot//webctrl_client";
    XCopyFile (szSrcFile, szTargetPath, INCLUDE_SUBDIR);
   
   
    if (svEdit2=TRUE) then
       CreateWebSite(szServerIPDefault,szServerPortDefault,szServernameDefault);  // 开始创建 IIS 站点
    endif;
    if (svEdit1=TRUE) then
      CreateVirtualDir(szServernameDefault);  // 开始创建 IIS 虚拟目录
    endif;
   
    CreateDataBase(destsvr,destsa,destpw);//创建和优化数据库
    
    szFileNa = TARGETDIR + "//Web.config";//修改Web.config文件 
    sztemp3="<add key=/"conn/" value=/"server=" + destsvr + ";database=SubjectSites;uid=" + destsa + ";pwd=" + destpw + ";/"><//add>";
    FileInsertLine (szFileNa, sztemp3, 3, REPLACE);

    Disable(STATUSEX);

    ShowObjWizardPages(NEXT);

 bOpt1  = FALSE;
    bOpt2  = FALSE;
    szMsg1 = SdLoadString(IFX_SDFINISH_MSG1);
   
Dlg_RebootDialog:
    szTitle = "安装完成";
    szMsg =   "    安装向导已经成功安装该系统。在使用该系统之前,必须重新启动计算机。";
    SdFinishReboot(szTitle, szMsg, SYS_BOOTMACHINE,"",0);
    return 0;
end;

//////////////////////////////////////////////////////////////////////////////
//
//  FUNCTION:   OnUninstallingFile
//
//  EVENT:      Uninstalling File event is sent before a file that is being uninstalled
//
//  ARGUMENTS:  File - full path of file being uninstalled
//
///////////////////////////////////////////////////////////////////////////////
function OnUninstallingFile(File)
begin
DeCreateDataBase();
DeleteVirtualDir();
end;

// --- include script file section ---

//////////////////////////
// 创建和优化数据库
//////////////////////////
function CreateDataBase(svSQLsvrf,svSQLusrf,svSQLpwdf)
    STRING szCmdLine1,szCmdLine2,szCmdLine21,szCmdLine3,szWaitTxt,tmpstr,tmpsql,szCmdLinebak;
    number nvFileHandle;
begin
    tmpsql = "SubjectSites";
                                                    
    szCmdLine1 = "/U "+svSQLusrf+" /P "+svSQLpwdf+" /S "+svSQLsvrf+" /Q /"exec sp_attach_db N'SubjectSites' , N'"+TARGETDIR ^"RootDataBase//SubjectSites.mdf'/"";
    if (LaunchAppAndWait("osql.exe", szCmdLine1,WAIT) < 0) then
        tmpstr="数据库创建失败!请确定您的系统中已安装 Microsoft SQL Server 2000和SP1!";
        SprintfBox (INFORMATION, "安装提示信息", tmpstr, "");
    endif;
    
    szCmdLine2 = "/U "+svSQLusrf+" /P "+svSQLpwdf+" /S "+svSQLsvrf+" /d "+tmpsql+" /Q /"update config set respath ='"+TARGETDIR^"//midres//'/"";
    if (LaunchAppAndWait("osql.exe", szCmdLine2,WAIT) < 0) then
        tmpstr="数据库优化失败!请联系相关人员或者手动安装!";
        SprintfBox (INFORMATION, "安装提示信息", tmpstr, "");
    endif;
   
    szCmdLine21 = "/U "+svSQLusrf+" /P "+svSQLpwdf+" /S "+svSQLsvrf+" /d "+tmpsql+" /Q /"update config set vpath ='res1'/"";
    if (LaunchAppAndWait("osql.exe", szCmdLine21,WAIT) < 0) then
        tmpstr="数据库优化失败!请联系相关人员或者手动安装!";
        SprintfBox (INFORMATION, "安装提示信息", tmpstr, "");
    endif;
    
    szCmdLine3 = "/U "+svSQLusrf+" /P "+svSQLpwdf+" /S "+svSQLsvrf+" /Q /"use sdjswoa ; exec sp_updatestats/"";
    if (LaunchAppAndWait("osql.exe", szCmdLine3,WAIT) < 0) then
        tmpstr="数据库优化失败!请联系相关人员或者手动安装!";
        SprintfBox (INFORMATION, "安装提示信息", tmpstr, "");
    endif;
   
    szCmdLinebak = "/U "+svSQLusrf+" /P "+svSQLpwdf+" /S "+svSQLsvrf+" /Q /"exec sp_detach_db 'SubjectSites'/"";
    OpenFileMode(FILE_MODE_APPEND);
    OpenFile (nvFileHandle,TARGETDIR, "uninstall.txt");
    WriteLine (nvFileHandle, szCmdLinebak);
    CloseFile (nvFileHandle);
    return 0;
end;

/////////////////////
//分离数据库
/////////////////////
function DeCreateDataBase()
  string svLine,tmpstr;
  number nvFileHandle;
begin
    OpenFileMode(FILE_MODE_NORMAL);
    if(OpenFile (nvFileHandle,TARGETDIR, "uninstall.txt")<0) then
    exit;
    endif;
    GetLine (nvFileHandle, svLine);
    if (LaunchAppAndWait("osql.exe", svLine,WAIT) < 0) then
        tmpstr="数据库分离失败!请手动分离!";
        SprintfBox (INFORMATION, "删除提示信息", tmpstr, "");
    endif;
    CloseFile (nvFileHandle);
    DeleteFile(TARGETDIR^"uninstall.txt"); 
end;

//////////////////////////
// 创建IIS站点
//////////////////////////
function CreateWebSite(szServerIPDefault,szServerPortDefault,szServernameDefault)
    STRING szCmdLine1,szCmdLine2;
begin
    if ((szServerIPDefault = "") || (szServerPortDefault = "")) then
        MessageBox ("您没有设定"+TMP_PRODUCT_NAME+"运行的服务器IP地址或端口!!IIS信息服务设置失败!/n请自行创建IIS站点,并将主目录设为:"+TARGETDIR,SEVERE);
    else

   
    szCmdLine1 = "/""+SUPPORTDIR^"mkw3site.vbs/""+" -r /""+TARGETDIR+"/" -i /""+szServerIPDefault+"/" -o /""+szServerPortDefault+"/" -t /"天辰开放式基础教育资源管理系统/"";
 
    if (LaunchAppAndWait("WScript.exe", szCmdLine1,WAIT) < 0) then
        MessageBox ("不能建立WEB 虚拟站点,没有找到 WScript.exe 或执行脚本错误.",SEVERE);
    endif;
  
          
    szCmdLine2= "/""+SUPPORTDIR^"mkwebdir2.vbs /""+" -c LocalHost -w /"天辰开放式基础教育资源管理系统/" -v /"res1/",/""+TARGETDIR^"//midres/"";
    if (LaunchAppAndWait("WScript.exe", szCmdLine2,WAIT) < 0) then
    MessageBox ("不能建立WEB 虚拟目录,没有找到 WScript.exe 或执行脚本错误.",SEVERE);
    endif;
    endif;
    return 0;
end;

//////////////////////////
// 创建虚拟目录
//////////////////////////
function CreateVirtualDir(VirtualFolder)
    STRING szCmdLine1,szCmdLine2,szCmdLinebak,szFileNa;
    number nvFileHandle;
begin 
     if (VirtualFolder = "") then
     MessageBox ("没能读取到虚拟目录的名称!请联系系统供应商!"+TARGETDIR,SEVERE);
     else
     szCmdLine1 = "/""+SUPPORTDIR^"mkwebdir.vbs /""+" -c LocalHost -w 1 -v /""+VirtualFolder+"/",/""+ TARGETDIR+"/"" ;
     if (LaunchAppAndWait("WScript.exe", szCmdLine1,WAIT) < 0) then
     MessageBox ("不能建立WEB 虚拟目录,没有找到 WScript.exe 或执行脚本错误.",SEVERE);
     endif;
          
     szCmdLine2 = "/""+SUPPORTDIR^"mkwebdir2.vbs /""+" -c LocalHost -w 1 -v /"res1/",/""+TARGETDIR^"//midres/"";
     if (LaunchAppAndWait("WScript.exe", szCmdLine2,WAIT) < 0) then
     MessageBox ("不能建立WEB 虚拟目录,没有找到 WScript.exe 或执行脚本错误.",SEVERE);
     endif;
     szFileNa = TARGETDIR^"//vdir.txt";
     szCmdLinebak =SUPPORTDIR^"adsutil.vbs"+" //Nologo   //T:300   delete   W3SVC/1/root/"+szServernameDefault;
     OpenFileMode(FILE_MODE_APPEND);
     OpenFile (nvFileHandle,TARGETDIR, "vdir.txt");
     WriteLine (nvFileHandle, szCmdLinebak);
     CloseFile (nvFileHandle);
     endif;  
     return 0;
end;

//////////////////////////
// 删除虚拟目录
//////////////////////////
function DeleteVirtualDir()
string svLine,szCmdLine;
number nvFileHandle;
begin
    OpenFileMode(FILE_MODE_NORMAL);
    if(OpenFile (nvFileHandle,TARGETDIR, "vdir.txt")<0) then
    exit;
    endif;
    GetLine (nvFileHandle, svLine);
     //szCmdLine = "/""+SUPPORTDIR^"adsutil.vbs /""+" -c LocalHost -w 1 -v /"midres/",/""+TARGETDIR^"//midres/"";
     if (LaunchAppAndWait("cscript.exe",svLine,WAIT) < 0) then
     MessageBox ("不能建立WEB 虚拟目录,没有找到 Cscript.exe 或执行脚本错误.",SEVERE);
     endif;
     szCmdLine =SUPPORTDIR^"adsutil.vbs"+" //Nologo   //T:300   delete   W3SVC/1/root/res1";
     if (LaunchAppAndWait("cscript.exe",szCmdLine,WAIT) < 0) then
     MessageBox ("不能建立WEB 虚拟目录,没有找到 Cscript.exe 或执行脚本错误.",SEVERE);
     endif;
     CloseFile(nvFileHandle);
     DeleteFile(TARGETDIR^"vdir.txt");
end;

function CheckIIS() // 示例:检查系统是否安装IIS
     NUMBER nvType, nvSize;
     STRING svvalue;
begin
     RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );
     if (RegDBKeyExist ("System//CurrentControlSet//Services//IISADMIN" ) = 1) then
     return (1);
     else
     return (0);
     endif;
end;   

////判断数据库连接是否正确
function connSQLDB(Server,UserName,Password)                           
  STRING connstr;  
  BOOL  bResult;  
  OBJECT  conn; 
  NUMBER State;
  begin                  
      bResult= TRUE;  
      State= 0;  
      set conn = CreateObject("ADODB.Connection");  
      if !IsObject(conn)then  
          return   FALSE;  
      endif;  
      connstr = "";  
      if   Password=""   then  
          connstr=connstr+"Provider=SQLOLEDB.1;Password=/"/"";    
      else  
      connstr=connstr+"Provider=SQLOLEDB.1;Password="+Password;  
      endif;  
      connstr=connstr+";Persist Security  Info=TRUE;User ID="+UserName;  
      connstr=connstr+";Initial Catalog=master";  
      connstr=connstr+";Data Source="+Server;  
      conn.ConnectionString=connstr;    
      try  
      conn.open();  
      conn.close();  
      catch  
          MessageBox("没有安装sql server2000或者填写的信息有误,请检查后再试!",WARNING);  
          State=conn.Errors.Item(0).NativeError;  
          bResult=FALSE;  
      endcatch;  
      set  conn =NOTHING;  
      return bResult;  
  end;

原创粉丝点击