以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]登录窗口测试连接成功后重启项目出错 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=188285) |
-- 作者:huaziqiao1976 -- 发布时间:2023/9/12 11:51:00 -- [求助]登录窗口测试连接成功后重启项目出错 Dim SQLServer As String Dim Database As String Dim Username As String Dim Password As String SQLServer = e.Form.Controls("TextBox5").Value \' 服务器地址 Database = e.Form.Controls("TextBox6").Value \' 数据库文件 Username = e.Form.Controls("TextBox7").Value \' SQL用户名 Password = e.Form.Controls("TextBox8").Value \' SQL密码 Dim ErrMsg As String Dim Conn As String ="Provider=SQLOLEDB.1;Data Source=" & SQLServer & ";Initial Catalog=" & Database & ";User ID=" & Username & ";Password=" & Password & ";Persist Security Info=False;" If Connections.TryConnect(Conn,ErrMsg) = False Then MessageBox.Show("数据源无法连通!原因:" & ErrMsg) Else FileSys.WriteAllText(ProjectPath & "Attachments\\ip.txt","Provider=SQLOLEDB.1;Data Source=" & SQLServer & ";Initial Catalog=" & Database & ";User ID=" & Username & ";Password=" & Password & ";Persist Security Info=False;", True) FileSys.WriteAllText(ProjectPath & "Attachments\\open.Txt","open",True) MessageBox.Show("数据源连通!需要重启") Syscmd.Project.Open(ProjectFile) End If 提示:从索引 0 处开始,初始化字符串的格式不符合规范。
|
-- 作者:有点蓝 -- 发布时间:2023/9/12 12:06:00 -- 把所有项目事件代码,登录窗口所有代码都发上来 |
-- 作者:huaziqiao1976 -- 发布时间:2023/9/12 12:19:00 -- BeforeConnectOuterDataSource Dim ipFile As String = e.ProjectPath & "Attachments\\ip.txt" Dim Open As String = e.ProjectPath & "Attachments\\Open.txt" \'数据源连接设置窗口是否打开的配置文件 Dim ip As String = FileSys.ReadAllText(ipFile) Dim close As String = e.ProjectPath & "\\Attachments\\Open.txt" Dim OpenText As String = FileSys.ReadAllText(close) If OpenText = "close" \'判断修改数据源信息传递过来的参 Return Else If e.Name = "GJ" Then If Filesys.FileExists(ipFile) Then e.C \'已配置好的数据源连接字符串, FileSys.WriteAllText(e.ProjectPath & "Attachments\\Open.txt","Close",False) \'MessageBox.Show("数据源已连通!") Return End If End If If Connections.TryConnect(ip) = False Then MessageBox.Show("请重新设置参数!") FileSys.WriteAllText(e.ProjectPath & "Attachments\\Open.txt","Open",False) \'置数据源检测开关状态为Open. e.C& e.ProjectPath & "Attachments\\UserInfo.mdb;Persist Security Info=False" Return End If End If BeforeOpenProject Dim s As String = FileSys.GetParentPath(e.File) & "\\Attachments\\ip.txt" If FileSys.FileExists(s) = False Then e.Cancel = True e.HideSplashForm = True \'这个文件是空文件也行 MessageBox.show("数据库连接文件" & "IP.txt" & "丢失,无法打开此项目!") Return End If AfterOpenProject Dim Open As String = ProjectPath & "\\Attachments\\Open.txt" Dim OpenText As String = FileSys.ReadAllText(Open) If OpenText = "Open" \'判断修改数据源信息传递过来的参数,决定是否打开开设置窗口 Forms("数据连接").open() Return Else Forms("创建单位").open() Return \'一定要写上,否则会报错! End If 登录窗口 Button2 click Dim SQLServer As String Dim Database As String Dim Username As String Dim Password As String SQLServer = e.Form.Controls("TextBox5").Value \' 服务器地址 Database = e.Form.Controls("TextBox6").Value \' 数据库文件 Username = e.Form.Controls("TextBox7").Value \' SQL用户名 Password = e.Form.Controls("TextBox8").Value \' SQL密码 Dim ErrMsg As String Dim Conn As String ="Provider=SQLOLEDB.1;Data Source=" & SQLServer & ";Initial Catalog=" & Database & ";User ID=" & Username & ";Password=" & Password & ";Persist Security Info=False;" If Connections.TryConnect(Conn,ErrMsg) = False Then MessageBox.Show("数据源无法连通!原因:" & ErrMsg) Else FileSys.WriteAllText(ProjectPath & "Attachments\\ip.txt","Provider=SQLOLEDB.1;Data Source=" & SQLServer & ";Initial Catalog=" & Database & ";User ID=" & Username & ";Password=" & Password & ";Persist Security Info=False;", True) FileSys.WriteAllText(ProjectPath & "Attachments\\open.Txt","open",True) MessageBox.Show("数据源连通!需要重启") Syscmd.Project.Open(ProjectFile) End If |
-- 作者:有点蓝 -- 发布时间:2023/9/12 13:38:00 -- 去掉窗口按钮里的【Syscmd.Project.Open(ProjectFile)】改为放到AfterOpenProject AfterOpenProject Dim Open As String = ProjectPath & "\\Attachments\\Open.txt" Dim OpenText As String = FileSys.ReadAllText(Open) If OpenText = "Open" \'判断修改数据源信息传递过来的参数,决定是否打开开设置窗口 Forms("数据连接").open() Syscmd.Project.Open(ProjectFile) Return Else Forms("创建单位").open() Syscmd.Project.Open(ProjectFile) Return \'一定要写上,否则会报错! End If |
-- 作者:huaziqiao1976 -- 发布时间:2023/9/12 13:41:00 -- 这样不是弹出两个窗口就重启了,参数都还没修改 |
-- 作者:有点蓝 -- 发布时间:2023/9/12 13:47:00 -- 这2个窗口改为模式窗口 |
-- 作者:huaziqiao1976 -- 发布时间:2023/9/12 13:52:00 -- 又变成关闭窗口就重启 |
-- 作者:huaziqiao1976 -- 发布时间:2023/9/12 14:07:00 -- 改成 Syscmd.Project.Exit() |
-- 作者:有点蓝 -- 发布时间:2023/9/12 14:08:00 -- 什么样的情况下需要重启?什么情况不需要重启?自己加个全局变量判断一下,符合条件再重启 |
-- 作者:huaziqiao1976 -- 发布时间:2023/9/12 14:20:00 -- BeforeConnectOuterDataSource 需要重新获得IP.TEXT修改后和登录参数时要重启 |