armand21
Member
Hi Everyone
I have ended coding a little WinForm project containing 5 tables (SqlServer2008) I m about to test it....When i m trying to Loggin ( through Login form) I m receiving the following error message
InvalidOperationException was unhandled : The connexion string property was not initialized
I have added a double arrow to point out where VS compiler is highlighting the error . The connexion variable is defined inside a Module file
I have spent several time trying to find out what is wrong with the connexion string i could not figure out
Please help
Following is an excerpt of code.
Public Class LogInForm
Private Sub LogInForm_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim strConnectionString As String = "ARMAND\HP;" + _
".\SQL2008EXPRESS;Database=CSE_DEPT;" + _
"Integrated Security=SSPI"
SqlConnection = New SqlConnection(strConnectionString)
Try
SqlConnection.Open()
Catch SqlExceptionErr As SqlException
MessageBox.Show(SqlExceptionErr.Message, "Access Error")
Catch InvalidOperationExceptionErr As InvalidOperationException
MessageBox.Show(InvalidOperationExceptionErr.Message, "Access Error")
End Try
If SqlConnection.State <> ConnectionState.Open Then
MessageBox.Show("Database Connection is Failed")
Exit Sub
End If
End Sub
Private Sub TabLogin_Click(sender As Object, e As System.EventArgs) Handles TabLogin.Click
Dim cmdString1 As String = "SELECT user_name, pass_word, faculty_id, student_id FROM LogIn "
Dim cmdString2 As String = "WHERE (user_name=@Param1 ) AND (pass_word=@Param2)"
Dim cmdString As String = cmdString1 & cmdString2
Dim paramUserName As New SqlParameter
Dim paramPassWord As New SqlParameter
Dim LogInTableAdapter As New SqlDataAdapter
Dim SqlDataTable As New DataTable
Dim SqlCommand As New SqlCommand
Dim selForm As New SelectionForm
paramUserName.ParameterName = "@Param1"
paramUserName.Value = txtUserName.Text
paramPassWord.ParameterName = "@Param2"
paramPassWord.Value = txtPassWord.Text
SqlCommand.Connection = New SqlConnection
SqlCommand.CommandType = CommandType.Text
SqlCommand.CommandText = cmdString
SqlCommand.Parameters.Add(paramUserName)
SqlCommand.Parameters.Add(paramPassWord)
LogInTableAdapter.SelectCommand = SqlCommand
----> LogInTableAdapter.Fill(SqlDataTable) <----------
If SqlDataTable.Rows.Count > 0 Then
'MessageBox.Show("LogIn is successful")
selForm.Show()
Me.Hide()
Else
MessageBox.Show("No matched username/password found!")
End If
SqlDataTable.Dispose()
SqlDataTable = Nothing
SqlCommand.Dispose()
SqlCommand = Nothing
LogInTableAdapter.Dispose()
LogInTableAdapter = Nothing
End Sub
I have ended coding a little WinForm project containing 5 tables (SqlServer2008) I m about to test it....When i m trying to Loggin ( through Login form) I m receiving the following error message
InvalidOperationException was unhandled : The connexion string property was not initialized
I have added a double arrow to point out where VS compiler is highlighting the error . The connexion variable is defined inside a Module file
I have spent several time trying to find out what is wrong with the connexion string i could not figure out
Please help
Following is an excerpt of code.
Public Class LogInForm
Private Sub LogInForm_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim strConnectionString As String = "ARMAND\HP;" + _
".\SQL2008EXPRESS;Database=CSE_DEPT;" + _
"Integrated Security=SSPI"
SqlConnection = New SqlConnection(strConnectionString)
Try
SqlConnection.Open()
Catch SqlExceptionErr As SqlException
MessageBox.Show(SqlExceptionErr.Message, "Access Error")
Catch InvalidOperationExceptionErr As InvalidOperationException
MessageBox.Show(InvalidOperationExceptionErr.Message, "Access Error")
End Try
If SqlConnection.State <> ConnectionState.Open Then
MessageBox.Show("Database Connection is Failed")
Exit Sub
End If
End Sub
Private Sub TabLogin_Click(sender As Object, e As System.EventArgs) Handles TabLogin.Click
Dim cmdString1 As String = "SELECT user_name, pass_word, faculty_id, student_id FROM LogIn "
Dim cmdString2 As String = "WHERE (user_name=@Param1 ) AND (pass_word=@Param2)"
Dim cmdString As String = cmdString1 & cmdString2
Dim paramUserName As New SqlParameter
Dim paramPassWord As New SqlParameter
Dim LogInTableAdapter As New SqlDataAdapter
Dim SqlDataTable As New DataTable
Dim SqlCommand As New SqlCommand
Dim selForm As New SelectionForm
paramUserName.ParameterName = "@Param1"
paramUserName.Value = txtUserName.Text
paramPassWord.ParameterName = "@Param2"
paramPassWord.Value = txtPassWord.Text
SqlCommand.Connection = New SqlConnection
SqlCommand.CommandType = CommandType.Text
SqlCommand.CommandText = cmdString
SqlCommand.Parameters.Add(paramUserName)
SqlCommand.Parameters.Add(paramPassWord)
LogInTableAdapter.SelectCommand = SqlCommand
----> LogInTableAdapter.Fill(SqlDataTable) <----------
If SqlDataTable.Rows.Count > 0 Then
'MessageBox.Show("LogIn is successful")
selForm.Show()
Me.Hide()
Else
MessageBox.Show("No matched username/password found!")
End If
SqlDataTable.Dispose()
SqlDataTable = Nothing
SqlCommand.Dispose()
SqlCommand = Nothing
LogInTableAdapter.Dispose()
LogInTableAdapter = Nothing
End Sub