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
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