只从inifile获取连接信息

时间:2015-11-21 11:48:54

标签: powerbuilder

我是powerbuilder的初学者。我构建应用程序,我想只从inifile指定登录窗口的连接信息源,以便其他方式不活动。这里是由连接对象向导自动生成的代码:

Choose Case is_connectfrom

    Case IS_USE_INIFILE                     /*  Populate Database Connection from INI file  */
        string ls_inifile = "C:\Users\3za\Documents\AA\pbtutor.ini"

        as_dbms         = ProfileString ( ls_inifile, "Database", "DBMS", "ODBC")
        as_database     = ProfileString ( ls_inifile, "Database", "Database", "")
        as_userid       = ProfileString ( ls_inifile, "Database", "UserID", "")
        as_dbpass       = ProfileString ( ls_inifile, "Database", "DBPass", "")
        as_logid            = ProfileString ( ls_inifile, "Database", "LogID", "")
        as_logpass      = ProfileString ( ls_inifile, "Database", "LogPassword",    "")
        as_server       = ProfileString ( ls_inifile, "Database", "Servername", "")
        as_dbparm       = ProfileString ( ls_inifile, "Database", "DBParm", "ConnectString='DSN=EAS Demo DB V125;UID=dba;PWD=sql'")
        as_lock         = ProfileString ( ls_inifile, "Database", "Lock", "")
        as_autocommit   = ProfileString ( ls_inifile, "Database", "AutoCommit", "false")

    Case IS_USE_REGISTRY                        /*  Populate Database Connection from Registry  */
        string ls_registrykey = "" + "\DataBase"

        If RegistryGet ( ls_registrykey, "DBMS",        RegString!, as_dbms ) <> 1 Then
            RegistrySet ( ls_registrykey, "DBMS",       RegString!, "ODBC" )
            RegistryGet ( ls_registrykey, "DBMS",       RegString!, as_dbms )
        End If
        If RegistryGet ( ls_registrykey, "Database",    RegString!, as_database ) <> 1 Then
            RegistrySet ( ls_registrykey, "Database",   RegString!, "" )
            RegistryGet ( ls_registrykey, "Database",   RegString!, as_database )
        End If
        If RegistryGet ( ls_registrykey, "UserID",      RegString!, as_userid ) <> 1 Then
            RegistrySet ( ls_registrykey, "UserID",         RegString!, "" )
            RegistryGet ( ls_registrykey, "UserID",         RegString!, as_userid )
        End If
        If RegistryGet ( ls_registrykey, "DBPass",      RegString!, as_dbpass ) <> 1 Then
            RegistrySet ( ls_registrykey, "DBPass",         RegString!, "" )
            RegistryGet ( ls_registrykey, "DBPass",         RegString!, as_dbpass )
        End If
        If RegistryGet ( ls_registrykey, "LogID",       RegString!, as_logid ) <> 1 Then
            RegistrySet ( ls_registrykey, "LogID",      RegString!, "" )
            RegistryGet ( ls_registrykey, "LogID",      RegString!, as_logid )
        End If
        If RegistryGet ( ls_registrykey, "LogPassword", RegString!, as_logpass ) <> 1 Then
            RegistrySet ( ls_registrykey, "LogPassword", RegString!, "" )
            RegistryGet ( ls_registrykey, "LogPassword", RegString!, as_logpass )
        End If
        If RegistryGet ( ls_registrykey, "Servername",  RegString!, as_server ) <> 1 Then
            RegistrySet ( ls_registrykey, "Servername",     RegString!, "" )
            RegistryGet ( ls_registrykey, "Servername",     RegString!, as_server )
        End If
        If RegistryGet ( ls_registrykey, "DBParm",      RegString!, as_dbparm ) <> 1 Then
            RegistrySet ( ls_registrykey, "DBParm",         RegString!, "ConnectString='DSN=EAS Demo DB V125;UID=dba;PWD=sql'" )
            RegistryGet ( ls_registrykey, "DBParm",         RegString!, as_dbparm )
        End If
        If RegistryGet ( ls_registrykey, "Lock",            RegString!, as_lock ) <> 1 Then
            RegistrySet ( ls_registrykey, "Lock",           RegString!, "" )
            RegistryGet ( ls_registrykey, "Lock",           RegString!, as_lock )
        End If
        If RegistryGet ( ls_registrykey, "AutoCommit",  RegString!, as_autocommit ) <> 1 Then
            RegistrySet ( ls_registrykey, "AutoCommit",     RegString!, "false" )
            RegistryGet ( ls_registrykey, "AutoCommit",     RegString!, as_autocommit )
        End If

    Case IS_USE_SCRIPT                          /*  Populate Database Connection from Script  */
        as_dbms         = "ODBC"
        as_database     = ""
        as_userid       = ""
        as_dbpass       = ""
        as_logid            = ""
        as_logpass      = ""
        as_server       = ""
        as_dbparm       = "ConnectString='DSN=EAS Demo DB V125;UID=dba;PWD=sql'"
        as_lock         = ""
        as_autocommit   = "false"


    Case Else

        Return -1

End Choose

Return 1

我尝试将IS_USE_REGISTRY case和IS_USE_SCRIPT case作为注释,代码正常工作,但仍然无法理解编译器的工作原理。

1 个答案:

答案 0 :(得分:0)

只需将上面的所有代码替换为

string ls_inifile = "C:\Users\3za\Documents\AA\pbtutor.ini"

    as_dbms         = ProfileString ( ls_inifile, "Database", "DBMS", "ODBC")
    as_database     = ProfileString ( ls_inifile, "Database", "Database", "")
    as_userid       = ProfileString ( ls_inifile, "Database", "UserID", "")
    as_dbpass       = ProfileString ( ls_inifile, "Database", "DBPass", "")
    as_logid            = ProfileString ( ls_inifile, "Database", "LogID", "")
    as_logpass      = ProfileString ( ls_inifile, "Database", "LogPassword",    "")
    as_server       = ProfileString ( ls_inifile, "Database", "Servername", "")
    as_dbparm       = ProfileString ( ls_inifile, "Database", "DBParm", "ConnectString='DSN=EAS Demo DB V125;UID=dba;PWD=sql'")
    as_lock         = ProfileString ( ls_inifile, "Database", "Lock", "")
    as_autocommit   = ProfileString ( ls_inifile, "Database", "AutoCommit", "false")

无论如何,这将从INI加载。它将填充您的登录窗口。如果您想从ini中的连接自动登录,则必须跳过调用登录窗口并手动编写connect using语句。