问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

已存在 程序的配置设置 (.ini) 连接 Oracle11g R2 里的数据库 连接数据库失败 求高手!!! 急急

发布网友 发布时间:2022-04-13 11:52

我来回答

1个回答

热心网友 时间:2022-04-13 13:22

下面是一个VB6的类的源代码,来自国*站的一个技术专家,类名:CSetting,可以读写ini配置文件,或者读写注册表配置。
Option Explicit
'Settings interface class
'Copyright ?2000 - Stan Schultes
'Written for VBPJ Getting Started September, 2000

'CSetting mode enum
Public Enum csModes
csModeRegistry = 0
csModeINI = 1
End Enum

'class member variables
Private m_eSaveMode As csModes

'mole-level variables
Private msININame As String 'name of .INI file
Private msAppName As String 'app name for settings

'INI setting APIs
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal SectionName As String, ByVal KeyName As String, ByVal Default As Long, ByVal FileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal SectionName As String, ByVal KeyName As String, ByVal Default As String, ByVal ReturnedString As String, ByVal StringSize As Long, ByVal FileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal SectionName As String, ByVal KeyName As String, ByVal KeyValue As String, ByVal FileName As String) As Long
'there is no WritePrivateProfileInt declaration...

'Error definitions
Private Const mklErrOffset As Long = vbObjectError + 512
Private Const mklErrNotNumeric As Long = mklErrOffset + 1
Private Const mksErrNotNumeric As String = "The setting value returned was not numeric"
Private Const mklErrWriting As Long = mklErrOffset + 2
Private Const mksErrWriting As String = "Error writing Setting "
Private Const mklErrReading As Long = mklErrOffset + 3
Private Const mksErrReading As String = "Error reading Setting "

Public Function Init(Optional ByVal AppPath As String, Optional ByVal AppName As Variant, Optional ByVal Mode As csModes = csModeRegistry)
'Set up class variables, default to Registry mode
If IsMissing(AppPath) Then
msININame = App.Path
Else
msININame = Trim$(AppPath)
End If
If IsMissing(AppName) Then
msAppName = App.EXEName
Else
msAppName = Trim$(AppName)
End If
'default to the app's .exe path
msININame = msININame & "\" & msAppName & ".ini"
' msININame = App.Path & "\" & msAppName & ".ini"
SaveMode = Mode
End Function

Public Function GetSettingStr(ByVal Section As String, ByVal KeyName As String, ByVal DefaultValue As String) As String
'returns a string setting
Dim lRet As Long
Dim sBuf As String * 128

On Error GoTo GetSettingStr_Error

If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
GetSettingStr = GetSetting(msAppName, Section, KeyName, DefaultValue)
Case Else
lRet = GetPrivateProfileString(Section, KeyName, DefaultValue, sBuf, Len(sBuf), msININame)
GetSettingStr = TrimNull(sBuf)
End Select
GetSettingStr_Exit:
Exit Function

GetSettingStr_Error:
Err.Raise mklErrReading, "CSetting.GetSettingStr", mksErrReading & "(" & Err & ", " & Error & ")"
End Function

Public Function GetSettingInt(ByVal Section As String, ByVal KeyName As String, ByVal DefaultValue As Integer) As Integer
'returns a numeric setting
Dim sSetting As String

On Error GoTo GetSettingInt_Error

If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
sSetting = GetSetting(msAppName, Section, KeyName, CStr(DefaultValue))
'check if value is numeric
If IsNumeric(sSetting) Then
GetSettingInt = CInt(sSetting)
Else
'match behavior of .INI return
GetSettingInt = 0
'or - return error if desired
'On Error GoTo 0 'disable handler to return error
'Err.Raise mklErrNotNumeric, "CSetting.GetSettingInt", mksErrNotNumeric
End If
Case Else
'returns 0 if not numeric
GetSettingInt = GetPrivateProfileInt(Section, KeyName, DefaultValue, msININame)
End Select
GetSettingInt_Exit:
Exit Function

GetSettingInt_Error:
Err.Raise mklErrReading, "CSetting.GetSettingInt", mksErrReading & "(" & Err & ", " & Error & ")"
End Function

Public Sub SaveSettingStr(ByVal Section As String, ByVal KeyName As String, ByVal Setting As String)
'saves a string setting
Dim lRet As Long

On Error GoTo SaveSettingStr_Error

If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
SaveSetting msAppName, Section, KeyName, Setting
Case Else
lRet = WritePrivateProfileString(Section, KeyName, Setting, msININame)
End Select
SaveSettingStr_Exit:
Exit Sub

SaveSettingStr_Error:
Err.Raise mklErrWriting, "CSetting.SaveSettingStr", mksErrWriting & "(" & Err & ", " & Error & ")"
End Sub

Public Sub SaveSettingInt(ByVal Section As String, ByVal KeyName As String, Setting As Integer)
'saves a numeric setting
Dim lRet As Long

On Error GoTo SaveSettingInt_Error

If Len(msAppName) = 0 Then Init
Select Case m_eSaveMode
Case csModeRegistry
SaveSetting msAppName, Section, KeyName, CStr(Setting)
Case Else
lRet = WritePrivateProfileString(Section, KeyName, CStr(Setting), msININame)
End Select
SaveSettingInt_Exit:
Exit Sub

SaveSettingInt_Error:
Err.Raise mklErrWriting, "CSetting.SaveSettingInt", mksErrWriting & "(" & Err & ", " & Error & ")"
End Sub

Public Property Let SaveMode(Mode As csModes)
'sets save mode, see csModes enum
m_eSaveMode = Mode
End Property

Public Property Get SaveMode() As Long
'returns save mode
SaveMode = CLng(m_eSaveMode)
End Property

Private Function TrimNull(ByVal InString As String) As String
'trims string at first Null character
Dim lPos As Long
TrimNull = Trim$(InString)
lPos = InStr(TrimNull, vbNullChar)
If lPos > 0 Then TrimNull = Left$(TrimNull, lPos - 1)
End Function

Private Sub Class_Initialize()
msININame = App.Path & "\" & App.EXEName & ".ini"
End Sub
使用方法:
在程序的全局模块中定义CSetting的类实例变量:(以下定义了两个,分别读写ini和注册表)
Public SetIni As CSetting '读写ini配置文件参数 '
Public SetReg As CSetting'读写注册表配置参数
在sub main 中初始化:(其中PATH_EXE是你的程序路径,放ini文件的路径)
Set SetIni = New CSetting
SetIni.Init PATH_Exe, App.Title, csModeINI

Set SetReg = New CSetting
SetReg.Init PATH_Exe, App.Title, csModeRegistry

这就可以随便用了。
dbPassword = SetIni.GetSettingStr(NameDB, "Password", "111111")
dbUserID = SetIni.GetSettingStr(NameDB, "UserID", "123456")
dbCatalog = SetIni.GetSettingStr(NameDB, "Catalog", "aaa")
dbDataSource = SetIni.GetSettingStr(NameDB, "DataSource", sky)

cnStr= "Provider=SQLOLEDB.1;Password=" & dbPassword & ";Persist Security Info=True;User ID=" & dbUserID & ";Initial Catalog=" & dbCatalog & ";Data Source=" & dbDataSource '
其它由你自己补充了。
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
...结构的施工分包给其他单位那么是不是EPC总承包就不能分包 Win11玩不了地平线4如何解决_Win11玩不了地平线4怎么办 Win11玩不了地平线4如何解决_Win11玩不了地平线4怎么解决 地平线5警告显卡内存过低怎么办 极限竞速地平线5闪退怎么解决 极限竞速地平线5闪退解决方法 怎样册除手机屏幕上(精品游戏)图标 烧结普通砖有哪些 烧结普通砖都有哪些 ...4年后的年龄与弟弟3年前的年龄和是35岁。今年哥与弟各几岁??_百度... ...等于弟弟7年后的年龄,哥哥4年后与弟弟3年前的年龄的和是35岁。哥哥... 大自考与小自考的主要区别? 湖州捷通汽车修理厂怎么样? 湖州南浔同创木制品厂怎么样? 湖州织里徐龙春制衣厂怎么样? 湖州南浔申奥家私厂怎么样? 有人驾驶和无人驾驶的到底谁更安全 湖州双林荣恒抛光磨料厂怎么样? 坦途智行低速自动驾驶无人车底盘和普通的无人车底盘之间的区别是什么? 湖州全力药用制品厂怎么样? 湖州织里龙涛制衣厂怎么样? 湖州艺创星空文化工作室怎么样? 湖州南浔尚玉木材加工厂怎么样? 湖州市南浔化工厂怎么样? 湖州织里金聪伟制衣厂怎么样? 无人驾驶大约多久会在全国普及? 湖州织里飞皓制衣厂怎么样? 湖州市善琏春风湖笔厂怎么样? 湖州吴兴盛通机械加工厂怎么样? 湖州陈艳茜影视工作室怎么样? 陶琳建议车主加强学习,智能汽车的驾驶与传统汽车有何区别? 大自考和小自考的区别是什么?学分互认适用于什么 请问露华浓粉底液怎么样? 经常听人说起露华浓24小时持妆粉底液,最近想入手,有哪位大神知道这款... hc-05 蓝牙串口通讯模块引脚怎么接单片机 有谁用过露华浓不脱色粉底液?怎么样?好用吗?请用过的姐妹发言!! 红薯淀粉怎么做甜品 红薯淀粉可以做什么甜品 新手求解!!!pl/sql登陆database没有选项是怎么回事啊 oracle就安装在本机(64位 11gR2) 手机丢了换了新手机,微信聊天记录能不能恢复 vivo怎么设置ai接电话? 中国移动出的和云镜CM02有哪些功能? 中国移动和云镜的行车记录仪视频怎么查看 中国移动和云镜CM02怎么样? 海尔中央空调125单风扇和双风扇差价 中国移动的和云镜CM51行车记录仪怎么样,好用吗? 我家房子屋顶的瓦片是 青黑色的,配什么颜色外墙瓷砖好看呢? 家里屋顶瓦片用黑色,外墙用什么颜色搭配协调 屋顶灰色瓦片安静的画面……是那首歌 芋头美味又营养,常吃芋头可以稳定血压吗? 感应水龙头灵敏度怎么调