Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 Data Connection Times Out

$
0
0
I haven't done any work with data in a long while and I figured it's time for me to start brushing up on it again. Right now I'm having an issue where I try to open up the data connection, but the program freezes and then stops... It just ends. It doesn't give me any error messages or anything. Currently this is what I'm doing:

Code:

    'This is a Console Application
    Private Sub Search(ByVal column As String, ByVal value As String, Optional ByVal firstname As String = "")
        'Let the user know that the connection wasn't setup properly
        If IsNothing(con) Then
            Console.WriteLine("There was an issue with initializing the data connection. Please restart the program.")
            Exit Sub
        End If

        'Setup a new command
        Dim cmd As New SqlCommand
        cmd.Connection = con

        'If the firstname variable is empty, then the user is searching for something other than by name(or they are searching by just the last name)
        If String.IsNullOrWhiteSpace(firstname) Then
            'Get all columns from the table(customer) where the cell in our column variable equals the value
            cmd.CommandText = String.Format("SELECT * FROM customer WHERE {0} = {1}", column, value)
        Else
            cmd.CommandText = String.Format("SELECT * FROM customer WHERE {0} = {1} AND fName = {2}", column, value, firstname)
        End If

        Try
            'Open the connection
            con.Open()
            'Setup a data reader
            Dim reader As SqlDataReader = cmd.ExecuteReader

            'Check if the reader has any rows
            If reader.HasRows Then
                Dim header As String = "Policy | First Name | Last Name"
                Dim row As String = String.Format("{0} | {1} | {2}", reader.Item(1), reader.Item(2), reader.Item(3))
                Console.WriteLine(header)
                Console.WriteLine()
                Console.WriteLine(row)
                Console.WriteLine()
                Console.WriteLine()
            Else
                Console.WriteLine("No rows found.")
                Console.WriteLine()
                Console.WriteLine()
            End If

            Call SearchMenu()
        Catch ex As Exception
            Console.WriteLine(ex.ToString)
        Finally
            con.Close()
        End Try

    End Sub

The way that I'm setting up the connection is like this:
Code:

con = New SqlConnection(My.Settings.EmpConnectionString)
The way I'm adding the database is through the VS wizard for a Microsoft SQL Server Compact 3.5 database. What could be causing it to time out and just abruptly end?

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>