1,105,226 Community Members

Invalid Operation Exception

Member Avatar
AaronDickey
Newbie Poster
5 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm having some issues with this code:

Imports System.Data.SqlClient

Public Class loginForm

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '--Connection string to POS database
        Dim loginFormConnection As New SqlConnection("SERVER = localhost\SQLExpress; DATABASE = POS; INTEGRATED SECURITY = true;")

        '--Check to see if Windows Point of Sale is being ran for the first time
        Try
            '--SQL command to check firstRun table in the database
            Dim firstRunCommand As New SqlCommand("SELECT * FROM firstRun")
            firstRunCommand.Connection = loginFormConnection
            '--Open the database connection
            loginFormConnection.Open()
            '--Datareader for firstRunCommand
            Dim firstRunDataReader As SqlDataReader = firstRunCommand.ExecuteReader
            '--Close the database Connection
            loginFormConnection.Close()

            '--Change the form based on results from reader
            If (firstRunDataReader.HasRows = True) Then
                firstRunButton.Hide()
            Else
                firstRunButton.Show()
            End If
        Catch ex As SqlException
            MsgBox("Cannot connect to Windows Point of Sale Database.", MsgBoxStyle.Information, "Error 0001")
        End Try
    End Sub

End Class

Every time I try to debug the application I get the following error:

A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll

If any one can give me some guidance I would be grateful.

Thank You

Member Avatar
AaronDickey
Newbie Poster
5 posts since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I solved my issue.

Member Avatar
tintin_14
Newbie Poster
1 post since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Imports System.Data.OleDb
Module Module1

Public conn As New OleDbConnection

Public Sub open()
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=reservation.mdb"
conn.Open()


End Sub

End Module

Member Avatar
Begginnerdev
Veteran Poster
1,141 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
0
 

Be sure to close the thread if you have solved your issue.

Thank you.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: