-- 作者:reachtone
-- 发布时间:2009/8/23 11:01:00
-- 继续纠错:BeforeOpenProject中的对话窗出错
为了动态建立外部数据库连接,我是把连接字符串保存在一个文本文件中的。每次项目启动时,在BeforeOpenProject事件中,对该连接字符串进行有效判断。代码如下:
Dim File As String = ProjectPath & "ConnConfig.ini" If FileSys.FileExists(File) = False Then CloseSplashForm() e.Cancel = True MessageBox.show("系统配置文件不存在,软件无法打开!","系统警告",MessageBoxButtons.OK,MessageBoxIcon.Warning) Else Dim Conn As New Data.Oledb.OledbConnection(FileSys.ReadAllText(File)) Try Conn.Open() Conn.Close() Catch ex as Exception CloseSplashForm() e.Cancel = True MessageBox.show("数据库连接错误, 请重新设置! ","系统警告",MessageBoxButtons.OK,MessageBoxIcon.Warning) End Try End if
以前如果连接出错,弹出的对话窗都是没问题的,但现在会出现以下错误:
此主题相关图片如下:4.jpg

[此贴子已经被作者于2009-8-23 11:01:34编辑过]
|