Results 1 to 9 of 9

Thread: [RESOLVED] Can't connect to SQL Server Express 2008 database

Threaded View

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Resolved [RESOLVED] Can't connect to SQL Server Express 2008 database

    When trying to connect to a SQL Server Express 2008 database, I receive the following error:

    Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed.
    Which occurs on my "connection" line:

    VB.NET Code:
    1. Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=dbISTme!.mdf;Integrated Security=False;User ID=test;Password=test1;User Instance=True")
    2.  
    3.         Dim command As New SqlCommand("SELECT COUNT(*) FROM Credentials WHERE UserID = @UserID AND Password = @Password", _
    4.                               connection)
    5.  
    6.         With command.Parameters
    7.             .AddWithValue("@UserID", Me.txtUserName.Text)
    8.             .AddWithValue("@Password", Me.txtPasssword.Text)
    9.         End With
    10.  
    11.         connection.Open()
    12.  
    13.         If CInt(command.ExecuteScalar()) = 0 Then
    14.            
    15.         Else
    16.             Me.DialogResult = Windows.Forms.DialogResult.OK
    17.         End If
    18.  
    19.         connection.Close()]

    I've worked with SQL CE databases in the past and I've never had a problem with them. The connection strings are a little bit different, so I think that might have something to do with it.

    Originally, I looked up that error and got a whole bunch of nonsense. I found two solutions that worked for most people, but they did not work for me. The fist was an issue with XP and SP2, which I'm Windows 7. The second resolution was to delete the SQLEXPRESS folder.

    Then I saw a post from another site:

    One thing to remember is that although user instances is the default when working with Visual Studio, it is not mandatory to use them, it is quite possible to attach to databases in the traditional way from SQL Express, to do this you just need to edit the connection string and delete the "user Instance=true". User Instances just make it easier (when it does work) to work with databases as though they were files.
    So, I deleted that line and got another error:

    An attempt to attach an auto-named database for file dbISTme!.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
    This seems like the most generic error ever. There's even less information about this error.

    I've made sure that the database uses the SQL authentication and not Windows and made sure my user, "test", has the correct permission.

    Anyone have any on ideas on what I'm doing wrong?

    Thanks
    Last edited by weirddemon; Jun 29th, 2010 at 09:23 PM.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

Posting Permissions

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



Click Here to Expand Forum to Full Width