1 Replies - 848 Views - Last Post: 16 May 2016 - 06:19 AM

#1 alobi  Icon User is online

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 21-January 13

Additional information: The ConnectionString property has not been ini

Posted 16 May 2016 - 02:45 AM

I am trying to connect to this access database but kept getting this error and I am not sure how to fix it
"An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll

Additional information: The ConnectionString property has not been initialized."
below is the code, It highlight this following line of code Myconnection.open()
Private Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
        Dim myconnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Vb.Net Security\SecurityGuard\SecurityGuardmdb.accdb;Persist Security Info=False")
        myconnection.ConnectionString = connstring
        'the query 
        myconnection.Open()
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [usertbl] WHERE [username] = '" & txtusername.Text & "' AND [password] = '" & txtpassword.Text & "'", myconnection)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        ' The following variable hold true if user is found atherwise it holds false
        Dim userFound As Boolean = False
        Dim Username As String = ""
        Dim Password As String = ""
        ' If found
        While dr.Read
            userFound = True
            Username = dr("Username").ToString
            Password = dr("Password").ToString
        End While
        'checking the result

        If userFound = True Then

            frmMain.Show()

        Else

            MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")

        End If
        myconnection.Close()

    End Sub

:code:

This post has been edited by modi123_1: 16 May 2016 - 06:18 AM
Reason for edit:: fixed botched code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Additional information: The ConnectionString property has not been ini

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13553
  • View blog
  • Posts: 54,081
  • Joined: 12-June 08

Re: Additional information: The ConnectionString property has not been ini

Posted 16 May 2016 - 06:19 AM

03	        myconnection.ConnectionString = connstring

Why are you overwriting the connection string after your used one to create the variable?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1