paulthepaddy
Well-known member
Hey
Frm_Home is the application starting form, which before anything calls the login form(Frm_Login)
So the login form opens, Calls Connectionstring sub which gets the SQLServer connectiong string
The login Form then calls GetDB which gives the Entity the dynamic connection string, connects and gets the user from the User entity and passes it back to the home form
Frm_Home is the application starting form, which before anything calls the login form(Frm_Login)
Public Class frm_Home Public CurrentUser As User Private db As ImageEntities Private Sub frm_Home_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim frm As New frm_Login If frm.ShowDialog = Windows.Forms.DialogResult.OK Then CurrentUser = frm.CurrentUser frm.Dispose() Try db = GetDB() Me.lbl_Welcome.Text = "Welcome " & CurrentUser.User_FirstName & " " & CurrentUser.User_LastName Catch ex As Exception End Try Else Application.Exit() End If End Sub
So the login form opens, Calls Connectionstring sub which gets the SQLServer connectiong string
Public Class frm_Login Public CurrentUser As User Private db As New ImageEntities Private Sub frm_Login_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load If My.Settings.SQLServer_Address = "" Then ConnectionSettings() End Sub Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click If Me.UsernameTextBox.Text = "" Or Me.PasswordTextBox.Text = "" Then MsgBox("Please Enter Username & Password") Exit Sub End If If IsConnectionAvalable() = False Then Exit Sub Try db = GetDB() Catch ex As Exception MsgBox("Failed To Connect To Server" & Environment.NewLine & "Please Check Connection Settings") Exit Sub End Try CurrentUser = (From U As User In db.Users Where U.User_UserName = Me.UsernameTextBox.Text AndAlso U.User_Password = Me.PasswordTextBox.Text Select U).First Me.DialogResult = Windows.Forms.DialogResult.OK Me.Close() End Sub
The login Form then calls GetDB which gives the Entity the dynamic connection string, connects and gets the user from the User entity and passes it back to the home form
Public Sub ConnectionSettings() Dim SQLConnectionDialog As New DataConnectionDialog() SQLConnectionDialog.DataSources.Add(DataSource.SqlDataSource) SQLConnectionDialog.SelectedDataProvider = DataProvider.SqlDataProvider SQLConnectionDialog.ConnectionString = My.Settings.SQLServer_Address If DataConnectionDialog.Show(SQLConnectionDialog) = Windows.Forms.DialogResult.OK Then My.Settings.SQLServer_Address = SQLConnectionDialog.ConnectionString Else SQLConnectionDialog.Close() End If SQLConnectionDialog.Dispose() End Sub Public Function GetDB() As ImageEntities Dim EntityBuilder As New EntityConnectionStringBuilder EntityBuilder.Provider = "System.Data.SqlClient" EntityBuilder.ProviderConnectionString = My.Settings.SQLServer_Address EntityBuilder.Metadata = "res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl" Return New ImageEntities(EntityBuilder.ToString) End Function
Last edited: