Author:水如烟
这个类使处理登录SqlServer服务器显得非常简单。
示例代码:
Public
Class
MainForm
Private gConnectionString As String
' 初始
Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mLoginInformation As New LzmTW.uSystem.uData.uSql.LoginInformation
With mLoginInformation
.ServerName = " 192.168.0.250,9001 " ' 服务器名称+端口号
.Database = " Northwind "
.Save() ' 保存至 x:/Documents and Settings/{用户}/Application Data/{组织名称}/{程序名称}/{版本号}/LoginInformation.dat
End With
End Sub
' 一般使用,它从配置文件中读取参数
Private Sub Button2_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
With mSqlLoginService
If .TestConnect() Then ' 如果连接不成功,弹出设置窗体
Me .gConnectionString = mSqlLoginService.LoginInformation.ConnectionStringBuilder.ConnectionString
Console.WriteLine( Me .gConnectionString)
' continue
Else
' exit ?
End If
End With
End Sub
' 重置登录信息
Private Sub Button3_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
mSqlLoginService.ResetLoginInformation()
End Sub
End Class
Private gConnectionString As String
' 初始
Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mLoginInformation As New LzmTW.uSystem.uData.uSql.LoginInformation
With mLoginInformation
.ServerName = " 192.168.0.250,9001 " ' 服务器名称+端口号
.Database = " Northwind "
.Save() ' 保存至 x:/Documents and Settings/{用户}/Application Data/{组织名称}/{程序名称}/{版本号}/LoginInformation.dat
End With
End Sub
' 一般使用,它从配置文件中读取参数
Private Sub Button2_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
With mSqlLoginService
If .TestConnect() Then ' 如果连接不成功,弹出设置窗体
Me .gConnectionString = mSqlLoginService.LoginInformation.ConnectionStringBuilder.ConnectionString
Console.WriteLine( Me .gConnectionString)
' continue
Else
' exit ?
End If
End With
End Sub
' 重置登录信息
Private Sub Button3_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
mSqlLoginService.ResetLoginInformation()
End Sub
End Class
重置效果:
如果要启用初始窗体,即SplashScreenForm,那么,代码示意如下:
Public
Class
MainForm
Private gConnectionString As String
Private Sub MainForm_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load
LzmTW.uSystem.uWindows.uForms.uMainForm.SplashScreenHelper.SendMessage( " 正在尝试连接数据库.... " )
Threading.Thread.Sleep( 1000 )
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
With mSqlLoginService
If .TestConnect() Then
LzmTW.uSystem.uWindows.uForms.uMainForm.SplashScreenHelper.SendMessage( " 连接成功。 " )
Me .gConnectionString = mSqlLoginService.LoginInformation.ConnectionStringBuilder.ConnectionString
Threading.Thread.Sleep( 1000 )
Else
LzmTW.uSystem.uWindows.uForms.uMainForm.SplashScreenHelper.SendMessage( " 连接数据库失败,请与系统管理员联系。程序将退出。 " )
Threading.Thread.Sleep( 1000 )
Me .Close()
End If
End With
End Sub
Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
mSqlLoginService.ResetLoginInformation()
End Sub
End Class
Private gConnectionString As String
Private Sub MainForm_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load
LzmTW.uSystem.uWindows.uForms.uMainForm.SplashScreenHelper.SendMessage( " 正在尝试连接数据库.... " )
Threading.Thread.Sleep( 1000 )
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
With mSqlLoginService
If .TestConnect() Then
LzmTW.uSystem.uWindows.uForms.uMainForm.SplashScreenHelper.SendMessage( " 连接成功。 " )
Me .gConnectionString = mSqlLoginService.LoginInformation.ConnectionStringBuilder.ConnectionString
Threading.Thread.Sleep( 1000 )
Else
LzmTW.uSystem.uWindows.uForms.uMainForm.SplashScreenHelper.SendMessage( " 连接数据库失败,请与系统管理员联系。程序将退出。 " )
Threading.Thread.Sleep( 1000 )
Me .Close()
End If
End With
End Sub
Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mSqlLoginService As New LzmTW.uSystem.uData.uSql.SqlLoginService
mSqlLoginService.ResetLoginInformation()
End Sub
End Class