dcsimg
Results 1 to 13 of 13

Thread: [RESOLVED] SqlClient Exception

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    467

    Resolved [RESOLVED] SqlClient Exception

    In running the code below, I am getting the exception noted at line 16. My guess is that there might be something wrong with the system.data.sqlClient, dll file, but I am only guessing. Does anyone have an idea what might be going on with this?

    The database, SQLBooks, is one that I downloaded from a text book. I have opened and used it in the past, using an earlier version of Visual Basic.

    Name:  ErrorMessage.jpg
Views: 257
Size:  14.1 KB
    Last edited by gwboolean; Jan 11th, 2019 at 11:20 AM. Reason: Forgot image

  2. #2
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,545

    Re: SqlClient Exception

    well I can't read line 16, so you will have to wait for somebody else
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    467

    Re: SqlClient Exception

    Sorry about that. I like to use screen shots, but no one else does. Try this:

    Code:
      Private Sub frmTitles_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'connect to books database
            BooksConnection = New SqlConnection("Data Source=.\SQLEXPRESS; AttachDbFilename=F:\VBDBSourceCode\VBDB\Databases\SQLBooksDB.mdf; Integrated Security=True; Connect Timeout=30; User Instance=True")
            'open the connection
            BooksConnection.Open()
        'establish command object
        TitlesCommand = New SqlCommand("Select * from Titles", BooksConnection)
        'establish data adapter/data table
        TitlesAdapter = New SqlDataAdapter()
        TitlesAdapter.SelectCommand = TitlesCommand
        TitlesTable = New DataTable()
        TitlesAdapter.Fill(TitlesTable)
        'bind controls to data table
        txtTitle.DataBindings.Add("Text", TitlesTable, "Title")
        txtYearPublished.DataBindings.Add("Text", TitlesTable, "Year_Published")
        txtISBN.DataBindings.Add("Text", TitlesTable, "ISBN")
        txtPubID.DataBindings.Add("Text", TitlesTable, "PubID")
        'establish currency manager
        TitlesManager = DirectCast(Me.BindingContext(TitlesTable), CurrencyManager)
        'close the connection
        BooksConnection.Close()
        'dispose of the object(s)
        BooksConnection.Dispose()
        TitlesCommand.Dispose()
        TitlesAdapter.Dispose()
        TitlesTable.Dispose()
      End Sub
    Line 16 is BooksConndection.Open()

  4. #4
    Fanatic Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    915

    Re: SqlClient Exception

    What is the exception's error message?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    467

    Re: SqlClient Exception

    Sigh. I am always short something. Here.

    System.Data.SQLClient.SQLexception: 'Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.'

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,951

    Re: SqlClient Exception

    The forum software doesn't much like screenshots, as it scrunches them down into little blurry messes before posting them.

    I've never seen that error before, and there appear to be a few solutions. First off, though, why do you have that UserInstance=True. I've never used that, so I don't know what it even does. If you don't have a specific reason to use that, then delete it, as that may solve the problem. If you do have a specific reason for it, then this SO link might be useful:

    https://stackoverflow.com/questions/...ance-of-sql-se
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    467

    Re: SqlClient Exception

    I am, at this point, taking the code as it exists in the file provided. Additionally, I have successfully opened this database in the past, using this code. I do not fully (make that little more than at all) understand what is going on with this code.

    I took your suggestion and set the connection string to the following.

    Code:
    BooksConnection = New SqlConnection("Data Source=.\SQLEXPRESS; AttachDbFilename=F:\VBDBSourceCode\VBDB\Databases\SQLBooksDB.mdf; Integrated Security=True; Connect Timeout=30")
    Obtained a new error message:

    System.Data.SqlClient.SqlException: 'An attempt to attach an auto named database for file F:\FBDBSourceCode\VBDB\Databases\SQLBooksDB.MDF failed. A database with the same names exists, or specified file cannot be opened, or it is located on UNC share.'

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    467

    Re: SqlClient Exception

    I do not know if this makes a difference, but I have noticed that in the file folder where the database is, there is no .idf file with it or any of the other databases.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,951

    Re: SqlClient Exception

    There are lots of options to connection strings, and I don't even pretend to know or understand them all. When I create a connection string, I generally just copy from one I've used in the past, but if I want to create one clean, I go to this site:

    https://www.connectionstrings.com/sqlconnection/

    (that's the page specific to the SQL Server .NET provider, so if I was looking for OleDB, or ODBC, I would go to a different page, of course)

    The simple connection string found in the example is what I usually use. If you don't know the reasons behind some of the pieces of the connection string...I'm totally with you on that...but you might also try the simpler version and see if it works. After all, with regards to that new error as well as the last one, all I can really say is: I've never used those parts of a connection string, so maybe you don't need to, either.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    467

    Re: SqlClient Exception

    Thanks, I will go check all of this out. The truth is, I have almost no understanding of what is going on with connections. I have been making an attempt to get away from using datasets and be able to code queries directly to the tables instead of dataset queries. It has been a mess that has lasted months. This crap really sucks, but I am still trying.

    Oh, in your previous suggestion I ended up going to a link in StackOverflow and ended up with a message on my computer claiming that my computer had been taken over and that I should call a number alleged to be Microsoft to get my computer bac. I immediately shut everything down and started the computer. I have been unable to see that there is any damage, but is there anything I should do about this?

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,951

    Re: SqlClient Exception

    No, except be pissed off.

    What you saw was a pretty blatant attempt to get you to do something bad, and your response was reasonable. I believe these happen when somebody attaches a malicious thing to an ad. They want to scare you into either clicking something or calling some number (the latter, in your case)...and THAT's when bad things happen. Every site deals with these, but sometimes they still slip through the filters.

    You can ignore the SO link without any problem, too, though I doubt the link itself is an issue. It's now irrelevant.

    There are LOTS of options for connection strings. You can spend considerable time studying all those options and figuring out when best to use each one. I tend to use the one that worked before, and that has been good enough for years. If I encounter a situation where it isn't good enough...then I'll learn something new. So, get a connection string that works for you, add to it only when you HAVE to. Otherwise, I do think it's a good thing to be able to deal with direct queries rather than doing things through the dataset wizard. Even if you end up using the wizard, it's good to know how to do it directly. Connection strings are the most obscure piece of that, though.
    My usual boring signature: Nothing

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    467

    Re: SqlClient Exception

    This seems like it might take awhile. I have gone to your latest suggested link and am trying to find something that will work. No joy yet. The reasons change, but I always end up not being able to open the database.

    At least getting a different reason tells me that I might be in the game. But then again, I have thought that before.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    467

    Re: SqlClient Exception

    I finally got there. It took two steps however. The connection string that worked for me was:

    Code:
    BooksConnection = New SqlConnection("Server=.\SQLEXPRESS; AttachDbFilename=F:\VDBDSourceCode\VBDB\Databases\SQLBooksDB.mdf; Database=BooksDB.mdf;Trusted_Connection=Yes;")
    However, a catalog file was required and I had to create one in SQL Express and attach the file to the server.

Tags for this Thread

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