我用connection对象连接数据库,寻找在刚使用软件前往指定文件写(数据库名、服务器、用户名、密码),再登陆直接从此文件中取出,如何实现在线等待谢谢!!!!

解决方案 »

  1.   

    可以使用注册表做中转,提供几个API,希望你能自己写出来
    RegCreateKey  :建注册表项
    RegSetValueEx :为某项赋值
    RegCloseKey   :赋值后请关闭
    RegQueryValueEx :查找该值
      

  2.   

    你的问题啥意思?
    就是把你现在连接的SQL信息写文件是还是不是?
      

  3.   

    '使用INI File保存配置,不过不安全
    Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As LongPublic Function GetINIString(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal nSize As Long, ByVal lpFileName As String) As StringOn Error GoTo On_Error
        
        Dim strTemp As String * 255
        
        Dim lngLength As Long
        
        lngLength = GetPrivateProfileString(lpApplicationName, lpKeyName, "", strTemp, nSize, lpFileName)
        GetINIString = Left(strTemp, lngLength)    Exit FunctionOn_Error:    MsgBox Err.Description, vbInformation
        Exit Function
        
    End Function
      

  4.   

    Private Sub Command7_Click()
               '保存数据库连接信息
        Open App.Path & "\login.txt" For Output As #1
            Print #1, Text5.Text
            Print #1, Text6.Text
            Print #1, Text7.Text
            Print #1, Text8.Text
        Close #1
        MsgBox "保存成功,请重新开启程序", vbInformation, "保存"
        Unload Me
    End SubPrivate Sub Command7_Click()
    Dim Ts as string
    dim  Strdatabase  AS STRING
    dim  Struid  as stringdim Strpwd  as stringdim  Strserver  as string
    If Dir(App.Path & "\Login.txt") <> "" Then
            Open App.Path & "\login.txt" For Input As #1
            Line Input #1, Ts
                Text5.Text = Ts
                Strdatabase = Ts
            Line Input #1, Ts
                Text6.Text = Ts
                Struid = Ts
            Line Input #1, Ts
                Text7.Text = Ts
                Strpwd = Ts
            Line Input #1, Ts
                Text8.Text = Ts
                Strserver = Ts
            Close #1
        Else
           MsgBox "数据配置文件丢失!", vbExclamation, "丢失"
           GoTo err:
        End Ifexit sub
    err:
    end sub