dcsimg
Results 1 to 10 of 10

Thread: [RESOLVED] Data Connection Times Out

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Resolved [RESOLVED] Data Connection Times Out

    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?

  2. #2
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: Data Connection Times Out

    Put a breakpoint on this line:

    Code:
    If IsNothing(con) Then
    Check to see if the variable "con" actually has something in it. As part of that If/End, you are exiting the sub-routine. My guess is that "con" may not contain anything.
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: Data Connection Times Out

    I've setup a breakpoint on the cmd.Connection = con line and it had con setup, but I'll do the IsNothing line right now... Same thing, everything looks to be setup properly.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,913

    Re: Data Connection Times Out

    So, if you place a breakpoint on the call to Open and then step to the next line, are saying that it doesn't ever get to any next line; it just freezes for a while and then the app unloads?

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,446

    Re: Data Connection Times Out

    "Microsoft SQL Server Compact 3.5 database." <--- that's your problem... you can't use the SQLClient name space against a SQL CE database... you need to use SQLCEClient instead... SQL CE is a stripped down version of SQL Server, so there are some capabilities that have been removed from it, an as a result, it needs a different adapter, connection, etc.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,913

    Re: Data Connection Times Out

    Quote Originally Posted by techgnome View Post
    SQL CE is a stripped down version of SQL Server
    Actually, it's not even that. SQL Server Express is a stripped down version of SQL Server but SQL Server CE is a completely different product. They just use the "SQL Server" brand to lend it credibility.

    Note that the ADO.NET provider for SQL Server CE is not part of the .NET Framework. It will be installed if you install SQL Server CE so, if you can't guarantee that all your users will have SQL Server CE installed, you need to deploy the appropriate DLLs with your app.

  7. #7

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: Data Connection Times Out

    you need to use SQLCEClient instead
    That explains the behavior then. I'll definitely change the namespace when I get back to my other computer tomorrow and report back to y'all. I guess in my defense, when I did work a little bit with databases, it was with Access. So I was use to the OLEDB namespace, but excuses excuses I know

    So, if you place a breakpoint on the call to Open and then step to the next line, are saying that it doesn't ever get to any next line; it just freezes for a while and then the app unloads?
    For the sake of clearing it up some more, it just freezes for a while and then the app completely closes out. It's as if when the connection tries to open, somebody hits the stop debugging button(control + alt + break) after a few seconds of freezing the UI and everything else for that matter.

  8. #8

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: Data Connection Times Out

    I changed the namespace to SQLCEClient and it did fix the connection timing out. There are some other problems with my code too, but they don't pertain to this question; I'm going to mark this thread as resolved. Thanks y'all.

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,913

    Re: Data Connection Times Out

    Quote Originally Posted by dday9 View Post
    I changed the namespace to SQLCEClient
    I assume what you actually did was change the namespace to SqlServerCe (FQN System.Data.SqlServerCe).

  10. #10

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: [RESOLVED] Data Connection Times Out

    Yep, it was a typo. The imported namespace is:
    Code:
    Imports System.Data.SqlServerCe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width